Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Showing posts with label QTP Basics Tutorials. Show all posts
Showing posts with label QTP Basics Tutorials. Show all posts

WebTables in UFT - 10 Key points

1. WebTable or html grid are integral part of html pages and a lot of application data is organised in WebTables. QTP provides different methods to interact with the webtable in the web application. In this remaining article, we will discuss key points to interact with the webtables. 
Below image shows how a webTable is divided into column and rows and data can be extracted from cell in the web table.


2. Verify if the table exist in the application
istbleExist=Browser("qaaqtp").Page("title:=.*").WebTable("name:= DataTable").exist

3. In case the table exist in the Page, we can get the count of rows and columns in the application as shown below:

iRowCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:= DataTable").RowCount
'' for each of the  row, get the column count for each row
For rownum=1 to iRowCnt
 iColCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ColumnCount(rownum) 
 MsgBox iColCnt
Next

4. Now we know the number of rows and columns in the table, we can extract cell information using the code below:
CellData= Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").GetCellData(rownum,colcnt)

5. We can perform action on object of specific type in a cell in the webTable based on the cell
ibtnCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable")
.ChildItemCount(4,3,"WebButton")
This will get the number of child items in a particular cell of particular type.

6. This will click on the 2nd  webbutton in row 4 and column 3 of the webtable.
Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItem(4,3,"WebButton",1).click

7. Using HTML DOM also, we can get count of objects in a webtable
ielemCnt = Browser("Google").Page("title:=.*").WebTable("name:=DataTable").object.getElementsbyTagName(strTagName).length

8. We can get row count of element based on the cell text as below:
irownum = object.GetRowWithCellText ("text to search",columnnum, startfromrownum)

9. We can work with webtable together with dynamic descriptive programming as shown below:
Set objDesc = Description.Create
objDesc("micclass").value = "WebElement"
objDesc("html tag").value = "TD"
Set childobjdesc=Browser("Google").Page("title:=.*").WebTable("name:=DataTable")ChildObjects(objDesc)

10. Using ChildItemCount and childItem, we can extract information from webTable as shown below:

Public Function findObjectinWebTable(strobjType,iRow,iCol)
 ''get child count of specific object type
 oChildCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItemCount(iRow,iCol,strobjType)
 If oChildCnt >0
  ''Perform action based on object type
  Set ChldItem = Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItem(iRow,iCol,strobjType,0)
 If (strobjType = "Link" or strobjType ="WebEdit") Then
  ChldItm.Click
  ElseIf(stobjType = "WebCheckBox") Then
  ChldItm.Set "ON"
 End If
End Function

Environment variable in UFT : 10 Key points

1. Definition - Environment variables are variables used across QTP Scripts/ all actions in a script/recovery scenario/function libraries in a UFT script.
Understand them as global variables for UFT Test Scripts.

2. Types of Environment Variables:
Environment variables are of 2 types: 
a. Built in Variables
b. User Defined Variables

3. Built -in variables are defined in QTP and can provide information on the QTP scripts and the operating system.

4. User Defined variables are again be divided into two types: 
       a. User Defined - Internal - defined at test level by adding a new environment parameter.
       b. User Defined - External - imported for an external xml file with parameters and values for parameters defined in the external file.




5. Steps to add user defined environment variables:

a.) In the test in which environment variable are to be added, Go to file -> Settings -> Environment.
b.) In variable type, select user defined. 
c.) Click on + icon, and add a new parameter with name and value.

6. To import from external file, check checkbox to load from external file and provide the path of the external file.

7. Environment variable for external file can be imported through code as shown below:

fileName = Environment.ExternalFileName

if (fileName = "") Then

    Environment.LoadFromFile("C:\testEnv.xml")

End If

8. Access and update environment variable in the script:


''Acessing an environment variable:

Testval =  Environment.Value("testing")

''Updating an user defined variable

Environment.Value("testing") = "testing2"

9. Example of environment variable xml file


<Environment>
 <Variable>
  <Name>Environment1</Name>
  <Value>ValueA</Value>
 </Variable>
 <Variable>
  <Name>Variable2</Name>
  <Value>ValueB</Value>
 </Variable>
</Environment>


10. Useful Reference: 


http://gareddy.blogspot.in/2010/12/qtp-environment-variables.html

http://qaautomationqtp.blogspot.in/2013/05/environment-variables-in-qtp.html

Summary

environment variable summary


Properties for object identification in QTP

QTP learns the properties of test objects to uniquely identify the object at run time. There are predefined set of properties for object classes in each environment.


Object are classified as Object classes for each environment. For e.g. environment Standard Windows environment as shown below will have all the test object class defined and defined are the mandatory and assistive properties to identify the object. Also we can set smart identification On for the object and the default ordinal identifier.to identify the object. 


To have a look at Object Identification properties for an object, Navigate to Tools>Object Identifier.


Let us understand the object Identification Window:


1. Environment: Lists all the environment for which objects are defined.


2. Object Classes:
List all the controls available for the environment selected.


3. Mandatory Properties:
These are the properties QTP always learns for the test object class selected.


4. Assistive Properties: In case object is not uniquely identified using the mandatory properties, there are some assistive properties which are learned to uniquely identify the object.


5. Smart Identification
is false by default, but can be checked for identification.


6. Ordinal Identifer: In case object is not identified using the above properties , Ordinal identifier is used to identify the object

List of Regular Expression for UFT/QTP

Regular expression are used to match input text with the pattern provided by regular expression engine. A pattern consists of one or more character literals, operators, or constructs. Below table explains the different regular expression patterns to identify the input text matches the expected pattern


Regular expression are used to validate the input text provided with the expected pattern. e.g : validating date format is correct or telephone number  provided is in correct format.



Reg. Expression

Description

( .)

 A dot matches single character (.) eg test. will match dot followed by any single character.example: testa, test5 

 [ab]

Matches either of the character in the list. e.g 23[ab] will match both 23a or 23b but not 23r

[^ab]

Matches all the characters excluding the the character in the list. e.g 23[^ab] will not match both 23a or 23b but will match23r,235 or 23 followed by any character other

 \b

Matches a word at boundary. e.g test/b will match entest but not entester

 [x-y]

Matches a single character in the range. e.g 23[a-d] will match 23a,23b,23c,23d but not 23r

 [^x-y]

Matches a single character not in the range. e.g 23[^a-d] will not match 23a,23b,23c,23d but 23r

 \B

Matches a word not at boundary. e.g test/b will match entest but not entester

 \W

Matches any non-alphaNumeric character excluding underscore

 \w

Matches any alphaNumeric character including underscore

*

Wildcard character matching the multiple occurence of preceding character. e.g rat* will match ra, rat, rattt, ............i.e multiple occurence of preceeding character t in this example.

 .*

Wildcard character matching the multiple occurence of preceding character.Preceeding character is . in case, so ra.* will match any string starting with ra

+

Similar to * but atleast one occurence of the character should match.e.g : rat+ will match rat but not ra

 ?

 matches zero or one occurrences of the preceding character. For example: ra?t match rt or rat only

 |

Matches either of the character seperated by |.example nes(t|l)ey will match nestey or nesley.

 \d

Matches a digit character

\D

Matches a non- digit/numeric character

\

marks the next character as special character or a literal. e.g \n is for new line ; \\ for \ and \d for a digit character

^

matches the pattern at start of line. e.g: ^test will match testing, tester but not autotest.

 $

matches the pattern at end of line. e.g: test$ will match autotest but not tester.

 |

Matches either of the character seperated by |.example nes(t|l)ey will match nestey or nesley.

 {}

Matches the start and end of qualifier expression. e.g a{4,5} will match aaaa or aaaaa

Reference:  Regular Expression Language - Quick Reference

Code to get title of all open browsers in QTP/UFT

We can get titles of all the open browser open using descriptive programming in QTP as explained in the code below:


Function GettitleAllbrowsers()
GettitleAllbrowsers = ""
Set objBrowser = Description.Create
objBrowser("micclass").Value = "Browser"
''Get all browsers instances in ObjBrowserLst 
Set objBrowserLst= Desktop.ChildObjects(objBrowser)
''Get the count of all the browsers open
browsercnt = objBrowserLst.count
For i=0 to objBrowserLst.count-1  
'Store title of the Page in a variable 
GettitleAllbrowsers = GettitleAllbrowsers + ">"+objBrowserLst(i).GetROProperty("title") 
Next 
Set objBrowser = nothing
Set objBrowser = nothing
End Function


For further manipulating the browser details using descriptive programming. Please go through the below articles:


Code to close multiple browsers except Quality Center/ALM in UFT/QTP?

How to close the IE browsers and Internet Explorer not responding windows forecefully -VBScript

Types of Environment variables in QTP / UFT

Below are the types of environment variables in QTP


1) Built-in - Used to extract test specific and machine/OS information. E.g ActionName, LocalHostName and OS to name a few.


2) User-defined Internal - Defined for the test and available only to the test in which it is defined.


3) User-defined External - Can be used across tests and can be loaded from an external xml file dynamically at run time or at the test level.


More Details on this topic, click on Environment Variable Loading




To view or not the test results in UFT

Once a test is executed in QTP/UFT, test results are displayed. UFT provides us the option to view the test results once the test execution completes. Follow following steps for the same.
  • Navigate to Options>General.
  • There is checkbox "View results when run session ends". In case the checkbox is checked, UFT results are launched automatically once the test execution completes. In case not checked, the results are not launched automatically once execution completes.


viewrunresults

Code to close multiple browsers except Quality Center/ALM in UFT/QTP?

Below Code shows how to close all browsers except browser based on the title of the browser in UFT / QTP.


Function CloseAllOpenbrowsersExcept(browsertitle)
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
''Get all browsers open 
Set oBrowserLst= Desktop.ChildObjects(oBrowser)
For i=0 to oBrowserLst.count-1  
'Verify the title of the browser and close the browser if it does not the title passed
'in the function
  If InStr(oBrowserLst(i).GetROProperty("title"), browsertitle) = 0 Then
    oBrowserLst(i).close  
  End If  
Next 
Set oBrowser = nothing
Set oBrowser = nothing
End Function


Similarly we can tweak the above code to close only a particular browser as shown below:


Function CloseOpenbrowserWithTitle(browsertitle)
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
''Get all browsers open 
Set oBrowserLst= Desktop.ChildObjects(oBrowser)
For i=0 to oBrowserLst.count-1  
'Verify the title of the browser and close the browser if it does not the title passed
'in the function
  If InStr(oBrowserLst(i).GetROProperty("title"), browsertitle) <> 0 Then
    oBrowserLst(i).close  
  End If  
Next 
Set oBrowser = nothing
Set oBrowser = nothing
End Function


Similarly we can close all browsers by removing the condition to check for title in the above code.


Function CloseAllOpenbrowsers()
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
''Get all browsers open 
Set oBrowserLst= Desktop.ChildObjects(oBrowser)
For i=0 to oBrowserLst.count-1  
'Verify the title of the browser and close the browser if it does not the title passed
'in the function
      oBrowserLst(i).close  
Next 
Set oBrowser = nothing
Set oBrowser = nothing
End Function

Difference between Actions and Functions in QTP/UFT 11.5


Comparison between Action and functions in QTP/ UFT 11.5 is explained in this article. We discuss on how action and functions are similar and difference between two in UFT 11.5/ QTP



Parameter
Action
Functions
Feature Type
Action is a feature provided by QTP/UFT
Function is a feature of VBScript
Return Value
We can pass as well as return multiple values using input and output parameters
A function returns a single value although values of multiple variable can be passed using public variable with global scope
Assets
An Action has local repositories, datatable, Active screen etc  associated with it
Function cannot have local repositories, datatable  and other QTP features associated with it
Multiple function can be created in an action
Multiple Actions cannot be created in a function.
Size and Performance
Size of the test increases with increase in number of actions as there is data table, OR associated with each of the test.
Performance of using function is better compared to action and consumes less size.
Actions
An Action is associated with a single test
Function library can be associated with multiple tests and can be loaded at runtime.
Maximum Allowed
There can be maximum 120 actions in a test and If any test has 120 actions in it, it will definitely not a good test script
There is no limit of number of function used in a test.
Maintenance Cost
Maintenance cost is higher in case of Action, as we need to open each test to make change at action. While multiple function library being vbs files can be updated easily.
Similarity between the Two
The purpose of using Actions or function is to provide modularity to the test scripts and should be used to create structured tests.
Extension
Extension of action script is .mts while function library can have extension as .vbs, .qfl.



How to remember Shortcut Keys in UFT/QTP

In this article, we will discuss on different shortcut keys in QTP/UFT. It is very difficult to understand each of the shortcut Keys and even does not make much change. But can remember the important one highlighted in bold green.

    File Menu


Creating Something New – When we create a new test or business component , it can be created with shortcut key combination with Key N.


New Test - Ctrl + N (For a test, we use Ctrl + N (for new))
New Business Component : Ctrl + Shift + N ((For a Business Component, we use Ctrl +Shift+ N (for new))
Function Library : Alt + Shift + N ((For a Function library, we use Alt +Shift+ N (for new))

Application area : Ctrl + Alt + N ((For an application area, we use ctrl + Alt + N (for new))

Opening something existing – So Open starts with O (So shortcut key combination will have one of the key as O and rest characters same as with new for test, business component, function library and application area.


Open Test : Ctrl + O
Open Business Component : Ctrl + Shift + O
Open Function Library : Alt + Shift + O

Open Application area : Ctrl + Alt + O

Adding new or existing– The shortcut key combination is created as ctrl+Shift + first letter of the component added.In case of existing, use Ctrl+ Alt instead of ctrl + Shift

Add new Test : Ctrl + Shift + T
Add new Business Component : Ctrl + Shift + B
Add new Application area : Ctrl + Shift + A
Add Existing Test : Ctrl + Alt + T
Add Existing Business Component : Ctrl + Alt + B
Add Existing Application area : Ctrl + Alt + A
Close: Ctrl + F4
Close Solution : Ctrl + Shift + F4
Save Current  : Ctrl + S
Save All : Ctrl + Shift + S

Edit Menu


Most of Edit option are same as other application, i.e copy using ctrl+c and paste using ctrl + v.

 Different ones are:
Comment : Ctrl + M
Uncomment : Ctrl + Shift + M
Indent : Tab
Outdent : Shift + tab
Complete word : Ctrl + Space
Argument Info : Ctrl + Shift + Space
Apply “With” to the script : Ctrl + W
Remove “With” : Ctrl + Shift + W

View Menu


One thing in common is all contain Ctrl+Alt

Solution Explorer: Ctrl + Alt + L
Toolbox : Ctrl + Alt + X
Properties : Ctrl + Alt + P
Data : Ctrl + Alt + D
Output : Ctrl + Alt + U
Errors : Ctrl + Alt + E
Tasks : Ctrl + Alt + K

Design Menu


Standard Checkpoint – F12
Existing Checkpoint – Alt + F12
Step Generator : F7
Check Syntax : Ctrl + F7

Record Menu


Record : F6
Stop Run/Recording : F4

Analog Recording : Ctrl + F3
Low Level Recording : Shift + F3

Run Menu


Run : F5
Run now : Shift + F5
Stop : F4
Run from step : Ctrl + F5
Step Into : F11
Step Over : F10
Step Out : Shift + F10
Insert Breakpoint : F9
Remove Breakpoint : Ctrl + F9

Clear All Breakpoints : Shift + Ctrl + F9

Object Repository Menu


Open Object Repository : Ctrl + R

ALM Connection Menu


ALM Connection : Ctrl + Q

Help: F1


How to create a database checkpoint in QTP

A database checkpoint compares the values returned by SQL query during checkpoint execution. Below are the steps to create a database checkpoint in QTP


  • Navigate to Insert>Checkpoint>Database Checkpoint.


  • Define whether to define SQL statement manually or using Microsoft Query


  • Select the database or query if previously defined as shown below.We select QT_Flight_32 database.Click on OK.

  • Select the required columns/tables to be selected in SQL and click on next button.


  • Define conditions for selected columns in the above step and define sorting criteria. Click Next>Next


  • Click on finish



  • Change the properties of database checkpoint and select whether to insert the checkpoint before or after current step and clcik on OK. A database checkpoint is created and inserted in the test.



Understanding Object Repositories Manager: Managing Objects

1.  How to Import Object Repository from xml file


Object repository can be loaded from an external xml file using object repository manager.


Importing and exporting Object Repositories to/from xml file


2.  How to export Object Repository to a xml file


Object repository can be exported to an external file using object repository manager.


3. Defining Objects manually in object repository 


      A new test object can be added manually using object repository manager. Below are the steps to add object manually in the object repository

Adding Object manually in Object repository

  • Navigate to Resources>Object Repository Manager
  • Navigate to Object>Define New Test Objects
  • Define new test Object with environment, name, and class of object and add description properties to object.
  • Click on Add to add object.
  • Save object repository as shared object repository


4.       Add Object to repository

  • User can add an object from  application without recording
  • Navigate to Resources>Object Repository Manager.
  • Navigate to Object>Add Objects
  • Focus on object to be added and click.
  • Object is added to repository.


5.       Navigate and Learn

  • User can add required objects from application using Navigate and Learn.
  • Navigate to Resources>Object Repository Manager.
  • Navigate to Object>Navigate and Learn or press F6.
  • Define the filter for objects to be added.
  • Click on learn button.
  • Object will be added to object repository


·          
Options of Working with object

6.       Update Object from Application

  • User can update objects from application with below steps
  • Navigate to Resources>Object Repository Manager.
  • Select an object to be updated. Please note updated object class should be same as the class of object by which it is to be updated.
  • Navigate to Object>Update from application
  • Object properties are updated