Pages

Saturday, September 18, 2010

QTP Environment Variables

swarupa Tags:
There are 3 types of Environment Variables
1.Built-In
2.Internal
3.External
Built-In :-These are predefine variables in Quick Test.They can be viewed under File—>Settings—>Environments Variables.They can be used to know the property values of the corresponding property names.
Example:- The following are few of  the list of environment variables.
OS = give the Operating System currently used on the system
OSVersion = gives the Operating System  version number
TestName = gives the current test name that is open
ProductDir = Folder path where the product is installed
1.Process to use Built-In Environment variables
go to Files—>Settings—>Environment the below window opens showing the list of all Built-In variables

image
remember any property name for which you want to see the corresponding value
Example1:-
a=Environment("ProductDir")
MsgBox a
when you run the above line of script in QT the output will be as follows
image
Example2:-
a=Environment("ProductName")
MsgBox a
output:-
image
Note :- The product names mentioned in QT should be written in the same as gives(case-sensitive) other wise you will get error like below
a=Environment("Productname")
MsgBox a
output
image
Internal Environment Variables:-
go to file—>settings—>Environment—>click on the dropdown box it will be showing you the option “User-defined variables” like below window
image
select “user-defined”—>click on green + symbol the below window opens –>enter the Name = x and Value = Welcome to the world of Automation—>click on OK—>OK—>it will be showing you the created “internal “ Environment variable.
image image
go to Expert view in QT and the below line of script
a=Environment("x")
MsgBox a
output:-
image
Note :- There is no restriction on creating the number of environment variables
External Environment variables:-
Step1:
open Notepad and the following lines of code(case-sensitive)
<Environment>
<Variable>
<Name>City</Name>
<Value>HYDERABAD</Value>
</Variable>
<Variable>
<Name>Area</Name>
<Value>Cyber-City</Value>
</Variable>
</Environment>
Note :- We can create any number of variables in XML file
save the above file as xml .i have saved it as “address.xml” file in “d” drive
Step2:-
Go to Files—>Settings—>Environment->user-defined—>select the checkbox “Load variables and values from External file” and at “file” browse and select the location where you have selected the “address.xml” file –> in the  below window it is showing the external environment variables added  in blue font—>click on apply-->OK
image
Step3:-
in expert view write the below line of script
a=Environment("Area")
MsgBox a
output:-
image
a=Environment("City")
MsgBox a
output:-
image 
Example :-External Environment Variables for Flight application
step1:-
Record the script for login in QT it will generate the script as follows
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "agent"
Dialog("Login").WinEdit("Password:").SetSecure "4c94b515b5ade453a27b0162cb431a4b265d2546"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Step2:-
go to Files—>Settings—>Environment—>user-defined—>and environment variables as follows
image image
image
click on apply—>OK
Step2:-
Go to expert view in QT
do the following changes in the generated script
agn = Environment.Value("agentname")
pwd = Environment.Value("password")
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set agn
Dialog("Login").WinEdit("Password:").Set pwd
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Note :- In  Environment.value() the values created internal should match the values given in the script
step3:-
Run now it will execute with the values you have given under environment tab
External:-
step A:-
create login.xml file as follows
- <Environment>
- <Variable>
<Name>agn</Name>
<Value>swarupa</Value>
</Variable>
- <Variable>
<Name>pwd</Name>
<Value>mercury</Value>
</Variable>
</Environment>
step B :- write the below line of code in QT Expert View
agn = Environment.Value("agentname")
pwd = Environment.Value("password")
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set agn
Dialog("Login").WinEdit("Password:").Set pwd
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Step C :-
Go to Files—>Settings—>Environment->user-defined—>select the checkbox “Load variables and values from External file” and at “file” browse and select the location where you have selected the “address.xml” file –> in the  below window it is showing the external environment variables added  in blue font—>click on apply—>OK it show as follows
image
step D :-
Run
it will execute with agentname as swarupa and password as mercury as mentioned in the xml file
LoadFromFile:-
we can direclty specify the file path like below in QT and run
Environment.LoadFromFile( "D:\login3.xml")
agn = Environment.Value("agentname")
pwd = Environment.Value("password")
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set agn
Dialog("Login").WinEdit("Password:").Set pwd
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close

Tuesday, September 14, 2010

How To Parameterize Radio Button

Go to Flight Reservation Window-->start recording for “New Order” the below lines of script is generated
image
Window("Flight Reservation").Activate
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("Flight Reservation").ActiveX("MaskEdBox").Type "121210"
Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Los Angeles"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "mohit"
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinEdit("Tickets:").Set "3"
Window("Flight Reservation").WinButton("Insert Order").Click
Step 2:
To parameterize the radio button
Go to object repository -->the below window opens -->click on first--> click on the symbol -->It opens the second window--> enter column name--> select “location in data table -->click on “OK”
clip_image005clip_image007
We can see the below change in QT
clip_image009
Enter the three values in data table under column name “Tickets_Types ” as
First
Economy
Business
NOTE:- all the above names of the radio buttons should be given in the same way as given the Flight Reservation Page “Case-sensitive” other wise QT won’t recognize and generates a run time error as
clip_image011try giving radio button name “First” as “first” and see .
Now run and see .It will execute the script for all the three values one at a time giving us three different iterations in “Results “
clip_image013

Monday, September 13, 2010

Descriptive Programming vs Object Repository : Which is better?

 

The answer isn’t simple.

1. In Expert View, DP and OR statements are written in the following manner:

'OR

Browser( "Google" ).Page( "Google" ).WebEdit( "q" ).Set "Google Search"

'DP

Browser( "title:=Google" ).Page( "title:=Google" ).WebEdit( "name:=q" ).Set "Google Search"

With DP, the properties are written with their corresponding values. OR, on the other hand, shows only a logical description of the object.

2. A DP parent will only recognize a child that has DP style layout. In other words, you CANNOT add a child to a DP parent that has its properties stored in the OR. Example:

'Will not work: Browser is DP whereas Page and WebEdit are OR

Browser( "title:=Google" ).Page( "Google" ).WebEdit( "q" ).Set "Google Search"

'Will not work: Browser and Page are DP whereas WebEdit is OR

Browser( "title:=Google" ).Page( "title:=Google" ).WebEdit( "q" ).Set "Google Search"

However, an OR parent will recognize both OR and DP style children:

'Will work: Browser is OR whereas Page and WebEdit are DP

Browser( "Google" ).Page( "title:=Google" ).WebEdit( "name:=q" ).Set "Google Search"

'Will work: Browser and Page are OR whereas WebEdit is DP

Browser( "Google" ).Page( "Google" ).WebEdit( "name:=q" ).Set "Google Search"

3. Writing good DP for Objects takes experience and skill. Even though DP has become extremely popular, improperly written DP can lead to performance issues, maintenance headaches etc. Its quite a different story with OR where you record the objects and QTP creates the hierarchy.

4. The user must be careful when using DP: it is case sensitive (except in the case of Web Applications). Do not confuse this with how VBScript works. If the value of a property ‘html id’ is ‘txtZip’ then it must be coded as ‘txtZip’, not ‘txtzip’ or ‘TXTZIP’. QTP will only find the object if the value is written exactly as in the Object Spy. Example (WebEdit’s name property is retrieved as ‘editNewName’):

'Correct description for WinEdit

Window("nativeclass:=Test").WinEdit( "name:=editNewName" ).Set "DP"

'Incorrect description for WinEdit

Window("nativeclass:=Test").WinEdit( "name:=editnewname" ).Set "DP"

'Incorrect description for WinEdit

Window("nativeclass:=Test").WinEdit( "name:=EDITNEWNAME").Set "DP"

5.Unlike OR, DP does not have auto-complete. All object descriptions must be coded out manually. This can be quite time consuming, and even frustrating for people who’re used to working with OR.

clip_image001[4]

Object Repository Auto Complete Feature

6.Unlike OR’s ‘Highlight in Application’ feature, when searching for an object hierarchy written in DP, you must execute the line of code to locate the object in the application. Another way would be to keep a record of all objects, which can be quite tedious.

clip_image002[4]

Object Repository Highlight in Application Feature

7. DP supports ChildObjects (to create the description object, you MUST use DP). Description object example:

Dim oDesc

Set oDesc = Description.Create

'Add a name property to the description

oDesc( "name" ).Value = "q"

'Add a html tag property to the description

oDesc( "html tag" ).Value = "INPUT"

8. On average, DP is slower than OR (note: on average!). With DP, QTP creates the an object from the provided hierarchy of DP and locates the object in the application before performing an event. Demo:

'OR: 9.74 seconds

For i = 0 to 99

Browser("Google").Page("Google").WebEdit("q").Set "QTP"

Next

'DP: 14.64 seconds

For i = 0 to 99

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"

Next

9. OR has a GUI which makes is easy to understand object hierarchies and maintain objects. DP hierarchies are code statements. Example:

clip_image003[4]

for DP

Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(Desc)

10. .Object is available to both DP and OR:

'OR

Browser("Google").Page("Google").WebEdit("q").Object.Value = "QTP"

'DP

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q").Object.Value = "QTP"

11. Objects have logical names in OR which makes it easy to identify them. Sadly, DP doesn’t, since its based on principles of a white-box.

12. This is strictly for OR, but at times you will notice that when working with applications, objects are added as: WebEdit_1, WebEdit_2, WebEdit_3 … WebEdit_n and so on. This can be extremely cumbersome to deal with, and it takes quite long to rename all the objects in OR to give them meaningful names.

13. Code written with DP can be easily copied/pasted onto other scripts or functions. With OR based scripts, a simple copy/paste will not result in a working script. All the repositories (local/shared) would have to be associated with the test to make it executable. Therefore, when creating test with many reusable components, its generally easier to work with DP in comparison to OR unless there is a comprehensive use of Shared Object Repositories 

14. Object Repositories have capabilities to perform single-point maintenance, whereas with DP, during changes, all objects undergo manual updates. In situations where there are several changes in the AUT, OR can prove to be a better performer

If you feel I have missed something and must be added or corrected, please post a comment and I will update this post, giving full credit to you. Thanks :)

QTP Descriptive Programming (DP) for Web

I'm going to explain and show QTP Descriptive Programming (DP) through Google Sets site:

image (click image to enlarge it)

The goal of the present QTP tutorial is to describe:

How to get number of controls (Links, Edits, Images, etc) with QTP DP.


Let's investigate Descriptive Programming on examples.
First of all, we should understand what Descriptive Programming means:

What is QuickTest Professional Descriptive Programming (QTP DP)?


Answer: QTP DP is a run-time processing of objects which are not located in QTP Object Repository.

I've created new QTP script which starts with http://labs.google.com/sets page.
This QTP script is simple enough:

Set Desc = Description.Create()

Desc("micclass").Value = "WebEdit"

Set Edits = Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(Desc)

MsgBox "Number of Edits: " & Edits.Count

And its result is:
image

As you can see, it works correctly and returns correct number of Edits on a page.
I'm going to explain this QTP script and answer the following question:

How does QTP Descriptive Programming work?

First of all, I've created new Description object: 

Set Desc = Description.Create()

Description object contains collection of properties, which identify any UI object such as a browser, a page, a dialog, a list, a button etc.
To specify that we want identify all Edits on browser's page I use "micclass" property:

Desc("micclass").Value = "WebEdit"

Note: the "mic" prefix in "micclass" stands for "Mercury Interactive Constant".

How do you know the class name ("micclass") of object?

Use Spy for that:
clip_image005
Open QTP object Spy and check recorded properties of object.
For example, these are properties of Edit:
sclip_image007
As you can see, there is "Class Name" property and its value - "WebEdit". So, "WebEdit" is a value of Class Name of all Edits located on Web page.
Note: "Class Name" is a synonym of "micclass".

Since we created Description object for all edit boxes, we can use this description to get all specified objects ( = edit boxes).
The next step returns the collection of all child objects (i.e. edit boxes) contained within the page:

Set Links = Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(Desc)

To get the number of found objects in a returned collection, we use Count property:

MsgBox "Number of Edits: " & Links.Count

And the result is 5 found Edits on Google Sets page:
clip_image011
So, this is a mechanism of QuickTest Professional Descriptive Programming.

Also, we can use the same code to get number of others objects - Links, Images, Buttons, etc.
For that I modified QTP script:

Function GetAllSpecificControls(Page, MicClass)

Set Desc = Description.Create()

Desc("micclass").Value = MicClass

Set GetAllSpecificControls = Page.ChildObjects(Desc)

End Function

Function GetAllEdits(Page)

Set GetAllEdits = GetAllSpecificControls(Page, "WebEdit")

End Function

Function GetAllButtons(Page)

Set GetAllButtons = GetAllSpecificControls(Page, "WebButton")

End Function

Function GetAllLinks(Page)

Set GetAllLinks = GetAllSpecificControls(Page, "Link")

End Function

Function GetAllImages(Page)

Set GetAllImages = GetAllSpecificControls(Page, "Image")

End Function

Set oPage = Browser("micclass:=Browser").Page("micclass:=Page")

MsgBox "Number of Edits: " & GetAllEdits(oPage).Count

MsgBox "Number of Buttons: " & GetAllButtons(oPage).Count

MsgBox "Number of Links: " & GetAllLinks(oPage).Count

MsgBox "Number of Images: " & GetAllImages(oPage).Count

The result of this QTP script is the following:

image image image image

Descriptive Programming --Types

 

Entering / Providing objects information directly into the test script is called Descriptive Programming.

In this method of script creation, we no need to have Object Repositories.
Advantages:

a) Descriptive Programming based Test scripts are faster in execution than Repository based Test scripts.

b) Scripts are portable (we can run these scripts from any machine easily)

c) Maintenance is easy (less amount of resources)

d) We can start Test Execution process even though Application is not ready.

Descriptive programming is basically 2 types.

1. Static Programming

2. Dynamic Programming

Static Programming

In this style of script generation, we provide objects information directly into the script.

Example:

Invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

dialog("text:=Login").Activate

dialog("text:=Login").Winedit("attached text:=Agent Name:").Set "swarupa"

dialog("text:=Login").Winedit("attached text:=Password:").Set "mercury"

dialog("text:=Login").Winbutton("text:=OK","width:=60").Click

window("text:=Flight Reservation").Close

Note:

1. Dialog, WinEdit and WinButton – Test Objects

2. text, attached text - Property names

3. Login, Agent Name:, Password:, OK,Flight Reservation - Property values or Logical Names of the Object

4. Activate, Set, Setsecure, Click - Methods

Note2:

If we feel one property information is not sufficient for recognizing the object uniquely, then we can provide more properties information by separating with commas.

Note 3:

If we want to get objects information (Test objects, properties and values), we can use object spy feature. This feature is available in Tools Menu, in local repository and in repository manager.

NOTE:-

If we want maintain ‘Objects information’ in centralized location then we can use Constants.
Steps:
Creating Constants:
Const Login="text:=Login", Agent="attached text:=Agent Name:"
Const Pwd ="attached text:=Password:", Ok="text:=OK"
Note: we can declare no of Constants in a line by separating with Camas (,), if we take other line then we have to use Const Statement again.
Creating a Library file
Place Constants in Notepad and save as .vbs file
Associate the Library file to QTP (File->Settings->Resources-> Click add (+) icon-> Browse path of the Library file->Click Apply and click Ok buttons
Otherwise, we can load the library file during run-time
Syntax:
ExecuteFile “Path of the Library file(.vbs)”

After that create the Test Script using Constants
Creating the Test Script using Constants:
Invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog(Login).Activate

Dialog(Login).Winedit(Agent).Set "swarupa"

Dialog(Login).Winedit(Pwd).Set "mercury"

Dialog(Login).Winbutton(Ok).Click

Advantages:
If we maintain Object Information in the centralized location, then we can handle modifications easily.
-------------------------------------------------------------------

Dynamic Programming

In this style of script generation, first we create description objects, provide properties information and use description objects in the test script.

Creating Properties Collection Objects

Set oLogin=description.Create

Set oAgent=description.Create

Set oPassword=description.Create

Set oOk=description.Create

Entering Properties Information into Objects

oLogin("text").value="Login"

oAgent("attached text").value="Agent Name:"

oPassword("attached text").value="Password:"

oOk("text").value="OK"

NOTE:- the above two parts to written in notepad with login.vbs and associate it from fileàsettingsàresourcesàclick on the + symbolàbrowse till the location where u have saved the file and say OK

And the below script in the QT

Generating Tests using Properties collection Objects

Invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog(oLogin).Activate

Dialog(oLogin).Winedit(oAgent).Set "swarupa"

Dialog(oLogin).Winedit(oPassword).Set "mercury"

Dialog(oLogin).Winbutton(oOK).Click

Note1: Create Description objects and put into one library file, by associating that library file, we can generate tests.

Note2: Dynamic programming is some difficult in preparation than static programming but maintenance is very easy.

QTP Regular Expression Example 2 using checkpoint on web

example 3
1. Open QTP and a new test.
2. Open Internet Explorer and open this URL http://www.worldtimeserver.com/current_time_in_IN.aspx
3. Click on Record in order to start recording.
4. Go to Insert-> Checkpoint->Text Checkpoint.
5. QTP will be minimized and mouse pointer will change into hand shape.
6. Click on time as shown in below screenshot.
clip_image003
7. Text Checkpoint Properties window will open with the text on which we clicked on, in red color.
8. In this window, on the right hand side of 'Constant' radio button click on pencil and paper button to open "Constant Value Options" button.
9. Check Regular Expression checkbox and in the value field type:(1[012]|[1-9]):[0-5][0-9] . Click OK. Again click Ok to come out of Text Checkpoint Properties window. NOTE:no spaces before and after while copy pasting the value and if the data is not copied properly it will prompt for adding the “\” it shows that there is something wrong in the given value
Re-check and give the proper value
clip_image006
Click here on the symbol and the window will open
clip_image008
Now enter (1[012]|[1-9]):[0-5][0-9] without spaces before and after the expression select the regular expression check box click on OK
clip_image010
The below screen appears
clip_image012click on OK
The below line of script is generated
Browser("Browser").Page("Current local time in").Check CheckPoint("Current local time in India")
10. Click on Stop in order to stop recording.
It will record only one line in the expert view:
Browser("Browser").Page("Current local time in").Check CheckPoint("Current local time in India")
Now you can refresh that website so as to see the current time and run this test again. It should pass.
Results page is as follows when we click on “run”
clip_image014
For datatable :-
Same as above except choosing the constant chose the datatable option in the 8th step above
And enter (1[012]|[1-9]):[0-5][0-9] (am|pm) in the QT I the datatable.

The regular expression object depicts a pattern of characters.

Example 2

Here we will talk about 2 Properties (Global Property, IgnoreCase property) and 2 Methods (Execute Method, Replace Method) of Regular Expression object.

Global Property

Below is an example of Global property of VBScript Regular Expression object. Set the Global to True and it matches the whole string and shows all the occurrences of patterns in the string.

Function regexp_function(ptrn, strng)

Dim regexp, Match, Matches

'declaring Regular expression Object

Set regexp = New RegExp

'Setting pattern

regexp.Pattern = ptrn

regexp.IgnoreCase = True

regexp.Global = True

Set Matches = regexp.Execute(strng)

For Each Match in Matches

result = result & "Match is found at position "

result = result & Match.FirstIndex & vbCRLF

Next

regexp_function = result

End Function

Msgbox(regexp_function("i", " mIssIssippi"))

This above code when run shows the below message box.

clip_image002

CASE2:-If Global Property is set to False then the result will be

clip_image004(it takes the first occurrence of the char i)

IgnoreCase property

Sets or returns a Boolean value that indicates if a pattern search is case-sensitive or not. The value of the IgnoreCase property is False if the search is case-sensitive, True if it is not. Default is False.

Function regexp_function(ptrn, strng)

Dim regexp, Match, Matches

'declaring Regular expression Object

Set regexp = New RegExp

'Setting pattern

regexp.Pattern = ptrn

regexp.IgnoreCase = True

regexp.Global = True

Set Matches = regexp.Execute(strng)

For Each Match in Matches

result = result & "Match is found at position "

result = result & Match.FirstIndex & vbCRLF

Next

regexp_function = result

End Function

Msgbox(regexp_function("is", "missISsippi"))

For above code where IgnoreCase is true it shows

clip_image007

If IgnoreCase is False then it shows

clip_image010

Execute Method

The Execute method also takes one string parameter and returns a Matches collection containing a Match object for each match found in string,.Executes any statements defined as strings at runtime.

If the regex could not match the subject string at all, MatchCollection.Count will be zero.

If the RegExp.Global property is False (the default), MatchCollection will contain only the first match.

If RegExp.Global is true, MatchCollection will contain all matches.

You can see the examples of Global Property and IgnoreCase Property to get a feel of Execute method.

Replace Method

Its syntax is:- Object.Replace(string1, string2)

String1 is the text string in which the text replacement is to occur.

String2 is the replacement text string.

Function ReplaceTest(ptrn, replStr)

Dim regexp, str

str = "mississippi"

Set regexp = New RegExp

regexp.Pattern = ptrn

regexp.IgnoreCase = True

regexp.Global=True

ReplaceTest = regexp.Replace(str, replStr)

End Function

MsgBox(ReplaceTest("is", "x"))

'the above function call replaces "is" with "x"

The above code shows

clip_image013

Regular Expression Object RegExp

Example1

Below example shows Test method, Ignore Case and Pattern property of Regular Expression object on Flight Reservation Application.

The below line in the code says that the user name should have last 5 letters as 'rupaR' and first letter can be anything except s,w and a. So xaxrupaR or wxvrupaR for example will work, but swarupaR  and waarupaR will not.

'MsgBox(RegExpTest("[^swa]rupaR", username))

Enter the below code in a new test in QTP and run it. When this example will work it will just open the Flight Reservation Application and close it.

Dim username

username = inputbox("enter username ")

MsgBox(RegExpTest("[^swa]rupaR", username))

If (RegExpTest("[^swa]rupaR", username))="Pass" Then

msgbox "Pass"

else

msgbox "Fail"

ExitAction

End If

SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4b.exe"

window("Title:=Login").WinEdit("AttachedText:=Agent Name:").Set username

window("Title:=Login").WinEdit("AttachedText:=Password:").Set "mercury"

window("Title:=Login").winbutton("Text:=OK").Click

window("Title:=Flight Reservation").close

Function RegExpTest(patrn, strng)

Dim regEx, retVal ' Create variable.

Set regEx = New RegExp ' Create regular expression.

regEx.Pattern = patrn ' Set pattern.

regEx.IgnoreCase = False ' Set case sensitivity.

retVal = regEx.Test(strng) ' Execute the search test.

If retVal Then

RegExpTest = "Pass"

Else

RegExpTest = "Fail"

End If

End Function

Regular Expression in QTP for Windows Application Flight

regular expression concept

Open Flight Reservation window-->open any order I have taken order no:-->the following window opens

clip_image002clip_image004

start recording

now go to file-->Fax order-->enter fax number-->click on send-->stop recording

clip_image006the following code generates

Window("Flight Reservation").Activate

Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..."

Window("Flight Reservation").Dialog("Fax Order No. 2").ActiveX("MaskEdBox").Type "1212121212"

Window("Flight Reservation").Dialog("Fax Order No. 2").WinButton("Send").Click

step2:- Right click on the ("Fax Order No. 2")-->go to “object properties”

clip_image009

click on the above symbol the below window opens

clip_image012clip_image017now remove 2 and give *. and select regular expression clip_image019 Fax Order No.*.-->click on OK the below change you can see clip_image021click on OK

RUN the test -->it will run

Now open another order number like Order No:7 now the details of fax are new but still your script will run as you have applied the concept of “Regular expression”