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

Showing posts with label uft. Show all posts
Showing posts with label uft. Show all posts

Running JavaScript in UFT on Page

In UFT,  we can run java script on a page using RunScript method as shown below. This can be very useful to perform operation on a page/element in the page through Java script.


Browser(...).Page(...).runscript("javascript statement")

XPath Object Identification in UFT descriptive programming

UFT also supports XPATH and css together with descriptive programming, object repository and DOM for object Identification.

Xpath stands for Xml Path. Below are some XPath examples to be used with UFT. Xpath and css are most widely used object identification way in selenium also.


Xpath examples:

Id: 

Browser(...).Page(...).weblink("xpath:=//a[@id='linkuft']").click

Attribute Value:

Browser(...).Page(...).weblink("xpath:=//a[@Atttribute='goodclass']").click

text:

Browser(...).Page(...).weblink("xpath:=//a[text()='UFT']").click 

partial attribute value

Browser(...).Page(...).weblink("xpath:=//a[starts-with(@attribute,'goodclass']").click

Browser(...).Page(...).weblink("xpath:=//a[contains(@attribute,'goodclass']").click

Browser(...).Page(...).weblink("xpath:=//a[ends-with(@attribute,'goodclass']").click


To know details on what is CSS and XPath and how to capture CSS or xpath of an element. refer to

XPath and CSS for selenium/UFT

We can use tools like firebug/firepath or IE developer tool to identify the xpath/css of an element.

xpath is really useful when element is not identified diretly based on Object repository properties and used to
identify an element based on relative element existence based on other elements in the tree.

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


Ordinal Identifier in QTP

While learning the objects, QTP tries to identify objects based on the mandatory and assistive properties of the object. In case the above properties are insufficient to uniquely identify the object. QTP uses the ordinal identifier properties to uniquely identify the object together with the madatory and assistive properties.


There are three type of Ordinal Identifier in QTP which are assigned as numeric integer value for the object based on the order occurrence of object in the browser.


The three types of ordinal identifier are described below:



Ordinal Identifier

Description

 Index Based

Based on the object in the window, An index value is assigned to object based on existence in the source code. Index value starts from 0.

Location Based 

The Location property is based on location of object, works vertically from top to bottom and then from left to right. value starts from 0.

Creation Time

The Creation Time property is used for browser objects mainly and used to identify multiple browsers based on the time the browser/page was open. Value starts from 0

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