Saturday, November 22, 2014

New Features in QTP 11.0?

Following are some features which are new in QTP 11 compare to QTP 10.

 1. XPath & CSS (Cascading Style Sheets) based Object Notification.
     XPath uses Path expressions to select nodes in XML document. The Node is
     selected by following a path or a step.
     For example nodename : selects all nodes with the name 'nodename'.
                                          / : selects from root node.
                                         // : selects nodes in the document from current node that matches the  s
                                              election, No matter where it is.
                                          . : selects the current node. 
                                         .. : selects the parent of the current node.
                                       @ : selects attributes. 
 2. Results viewer have been improved by pie charts, summary data & statics for both current and  previous test runs.
 3. Recording using Firefox is now available.
 4. Weakness of QTP 10 was ordinal identification feature which is overcome with “Visual Relation Identifier”. Now, object identification can be done with neighboring objects.
 5. Automatically parameterize steps feature is also available in QTP 11. Now, We can instruct at the end of Record Session.
 6. Sliverlight Add-in & Silverlight support is also available now.
 7. Easy Regular Expression with help of Regular Expression Evaluator & with Syntax Hint.  

What is the General Process of Capturing Tool Tip via QTP ?

General Process of Capturing Tool Tip via QTP:
1. Hover your mouse to check whether UI element has any tool tip assosiated with it.
2. If Yes, Use 'Object Spy' and check properties which contain Tool Tip Value.
3. Mostly, you will fing Tool Tip in 'Title' Property.
4. Use GetRoProperty to fetch the value.

Ways to Capture Tool Tip via QTP
There are 4 ways by which we can capture Tool Tip in QTP. These are from:
1. Link 2. Image 3. X Path 4. CSS

1. With Link ( If there is any link on a website and you hower the mouse over the Link, a tool Tip appears. Now, how to capture the same with our tool.
msgbox Browser ("Edit Experise- QTPExpertise"). Browser: Edit  Experise- QTPExpertise
Page ("Edit Experise- QTPExpertise"). |__ Page:  Edit Experise- QTPExpertise
Frame ("Result"). |__Frame: Result
Link ("Expore More"). |__Link: Explore More" GetRoProperty ("title")
                                                                                ______________________________________
Properties | Operation ______________________________________
o   Native o   Identification
Properties | Values
outertext |
target |
text |
title | QTP Expertise Homepage
________________________________________________________________________________
From Image 
( If there is any image on a website and you hower the mouse over the image, a tool Tip appears. Now, how to capture the same with our tool).
msgbox Browser ("Yahoo!"). Bowser: Yahoo!
Page ("Yahoo"). |__ Page: Yahoo
Webelement ("India").  |__ Web element: India
GetRoProperty ("title")
_________________________________________________________________________________
Using X Path
(Suppose you are creating account and there are informations like First name, Middle name & Last Name where Middle Name is optional. How to capture the same)
First Name*
Middle Name (optional)
Last Name*
To Capture, Middle Name, whic is optional, Here, we will take the help of X Path. We will follow the steps below:
- Open this link in Google Chrome Browser.
- Right Click on the page and click 'Inspect Element'.
- Use Little magnifying glass on left and inspect 'middle name edit box'.
- Highlight the row > Right Click > Copy X Path
          ( Suppose it is //*[@id='ss2'])

It will look like:
msgbox Browser (" WebAccount: Tooltip"). Page ("WebAccount: Tooltip").
webelement ("xpath := //*[@id='ss2']").
GetRoProperty ("innerhtml")
_________________________________________________________________________________
Using CSS 
(Suppose you are creating account and there are informations like First name, Middle name & Last Name where Middle Name is optional. How to capture the same)
 First Name*
 Middle Name (optional)
 Last Name*
 To Capture, Middle Name, which is optional, Here, we will take the help of CSS. We will follow the steps below:
 - Open this link in Google Chrome Browser.
 - Right Click on the page and click 'Inspect Element'.
 - Use Little magnifying glass on left and inspect 'middle name edit box'.
 - Highlight the row > Right Click > Copy CSS Path
 ( Suppose it is //*[@id='dp2'])

It will look like:
msgbox Browser (" WebAccount: Tooltip"). Page ("WebAccount: Tooltip").
webelement ("csspath := //*[@id='dp2']").
GetRoProperty ("innerhtml")

Dictionary Objects in QTP ?

What are Dictionary Objects?
They store information in name/value pair.
How these are Different from Arrays?
Look like similar to Array but the difference is
1. Keys are used to identify the items in a dictionary object.
2. No need to call ReDim to chnge the Size.
3. When deleting an item from Dictionary, remaining items will automatically shift up.
4. They can’t be multi-dimensional.
Ilustration with an Example
Let’s understand the concept with an example:
Dim Dict
Set Dict = Server.CreateObject (“ Scripting Dictionary”)
Dict.Add “book1”, “Gandhi”
Dict.Add “book2”, “Nehru”
Dict.Add “book3”, “Indira”
Response.Write (“The book 2 is:” &Dict.item(“book2”))
Output: The book 2 is Nehru
Dictionary Objects
Properties: Compare Mode, Count, Item & Key.
Methods: Add, Exists & items.

Virtual Objects in QTP?

Virtual Objects
It enables to record and run tests on Objects that are not normally recognized by Quick tests.
For Example: If we try to record activities in a Chess Game,
Windows ("Chess"). activate
Windows ("Chess). click 82, 65
Windows ("Chess). click 17, 25
Windows ("Chess). click 34, 55
Windows ("Chess). click 74, 28
Windows ("Chess). click 82, 45
From the above code, we will never know what is 82,65 or 17,25.... To make clarity of steps, we can use Virtual Objects.
How to create a Virtual Object
  1. Tools> Virtual Objects> Virtual Object manager
  2. (Virtual Object Manager Wizard opens)
  3. New> Map to a standard class
  4. Choose: object/ Button/ Table/ List/ Checkbox/ Radio Button
  5. In our case, suppose there is a button on Chess Board as 'New Game' to start new game. and another button as 'Withdraw' to Withdraw from game. For that we will choose 'Button' and click on 'Mark Object'.
  6. A Cross-hair Pointer will appear to record Object. It's Width and Height is recognized as 82,45. Rename this Button as 'New'.
  7. Now, you will see the message:" Do you want to create another virtual object?' Yes/No
  8. Similar grounds, create another virtual object as 'Withdraw'.
  9. Now, There are 64 Boxes 8 Rows and 8 Columns. It is difficult to create 64 Buttons. rather, we can create one Virtual Object as 'Table'. Here, We will choose 'Table' and Mark the entire table with Cross-Hair Pointer.
In our example, Available Virtual Objects are:
  VoCollection()
|_________ New
|_________ Table
|_________ Withdraw
Now, If we will start recording, our script will look like:
Windows ("Chess"). activate
 Windows ("Chess). VirtualButton ("New"). click 
 Windows ("Chess). VirtualTable ("Table"). SelectCell 1,1
 Windows ("Chess). VirtualTable ("Table"). SelectCell 4,4
Windows ("Chess). VirtualTable ("Table"). SelectCell 8,2
 Windows ("Chess). VirtualButton ("Withdraw"). click
By using, Virtual Object, Code is easy t understand.

Please Note:   
  1. Object Spy can't be used here.
  2. QTP supports Virtual Object only in Normal Recording.
  3. Virtual Objects Created are stored as .vot fileat the location:
<QuickTestInstallation folder>\dat\VoTemplate

Recovery Scenarios in QTP?

What is recovery scenario in QTP?
While executing a test, some unexpected error and event may occur. To overcome this we take the help of Recovery Scenario. The Recovery Scenario Consist of following steps:
1. Create a New Scenario in Recovery Scenario Manager.
2. Identify trigger Event.
3. Set the Recovery Operations.
4. Set Post Recovery Test Run Operations.
5. Name the Scenario.
6. Associate the scenario with our test.

Trigger Event: when an unexpected events or errors invoke. Following types of Triggers:
o POP-UP window: QTP identify POP-UP window based on window title and textual content.
o Object State: object state is identified by its properties.
o Test Run Error: when test run result value is failed it is identified.
o Application Crash: this state is identified by predefined list of application.
Nature of Error can be any Error like:
o Item in List/Menu is not unique.
o Item in List/Menu is not found.
o More than one objet responding to physical description.
o Object is disabled.
o Object not found.
o Object not visible.
Recovery Operation: Operation needed to perform for running the remaining test script. Following types of Recovery Operations are there in QTP:
o Keyboard or mouse operation.
o Close Application Process.
o Function call.
o Restart Microsoft Windows.
Post-Recovery Test Run Option: after recovering from unexpected error where to start the remaining test execution. It can be any of the following:
o Repeat Current Step & Continue.
o Proceed to Next Step.
o Proceed to Next Action or component iteration.
o Restart Current Test Plan.
o Stop Test Run.
Name the Recovery Scenario.
Click Finish button Summary Screen with ‘Option to add to Current Test’ appears.
Associate recovery scenario Specifying either associate to the current test or all new test. By Selection the Location from File> Settings> Recovery> +
o Either Select from Scenario’s
o or Add Scenario.

Regular Expressions and some useful Examples.

Regular Expressions

Manytimes, while creating a regular expression in Real Testing Environment, we face some problems. Here, I have ried to extract out regular expressions, which we can apply directly as it is. Some of these scenarios are:
Pattern for Password
Pattern: [a-zA-Z]\w{3,14}
Matching Text: abcd, aBc45DSD_sdf, password
Non-Matching Text afv, 1234, reallylongpassword
The password's first character must be a letter, it must contain at least 4 characters and no more than 15 characters and no characters other than letters, numbers and the underscore may be used.
Pattern for IP Address
Pattern: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
Matching Text:  match any IP address just fine, but will also match 999.999.999.999 as if it were valid IP address.
Pattern for Visa Credit Card
Pattern: ([4]{1})([0-9]{12,15})
Matching Text: 4125632152365, 418563256985214, 4125632569856321
Non-Matching Text: 3125652365214, 41256321256, 42563985632156322
Validate against a visa card number. All visa cards start with a 4 and are followed by 12 to 15 more numbers.
Title Alphanumeric
Pattern: [a-zA-Z0-9]+$
Matching Text: 10a, ABC, A3fg
Non-Matching Text: 45.3, this or that, $23
Matches any alphanumeric string (no spaces).
Pattern for Six Integer Indian ZIP Code
Pattern \d{6}
Matching Text: 333333, 555555, 234455
Non-Matching: Text abcd, 1324, as;lkjdf
Matches 6 numeric digits, such as a zip code.
Pattern for Indian Currency
Pattern: \INR(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?
Matching Text: INR0.84, INR123458, INR1,234,567.89
Non-Matching Text: 12345, 1.234INR
This matches Indian currency format with INR as Ruppee sign. INR value must have at least one digit and may or may not be comma separated. Paisa value is optional.
 Matching a Valid Date
19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]) matches a date in yyyy-mm-dd format from between 1900-01-01 and 2099-12-31, with a choice of four separators. The year is matched by (19|20)\d\d.

Difference between GetTo Property & GetRo Property?

GetToProperty

  • returns the value of the Property from the Test Object's description ie Value used by QTP to identify object.
  • Used to enumerate all properties of an object used for identification
  • Example (when object in OR) 
systemutil.run "iexplore.exe
Browser ("Google").navigate "http://yahoomail.com"
xyz = Browser ("Google").Page ("yahoomail:").webedit ("login").GetRoProperty ("name")
msgbox xyz

  • Example (When object is NOT in OR)
Set obj = Browser ("name:= Sign in to Yahoo"). Page ("title:= Sign in to Yahoo"). webedit (html id := username)
msgbox obj.GetToProperty ("html id")


GetRoProperty
  • allows us to get the current value of a test object.
  • Example
Print Browser ("A"). Page ("B"). Weblist ("C). GetRoProperty ("Select item index")