QTP – Descriptive Programming (DP) 4 (Creating a Test Script)

by Anshoo Arora on August 10, 2009 | QTP/UFT | 117 Comments

This is the last article in our Descriptive Programming series and will cover a simple login process using 100% DP. I have purposely created the example to be very high-level to make sure its quit easy to understand. However, if you feel more examples on this concept will help, I’ll be more than happy to create a Part V of this series with only real-world examples of DP in action.

We will use the HP/Mercury Demo Website for this example.

Following is the process I am going to follow to complete this process. In your application however, you can use the process that best suits your needs, but for the purposes of this lesson, I will keep it quite basic:

  1. Launch Browser.
  2. Check whether the correct browser opened.
  3. Ensure the userName, password edits and the Sign-In button exist.
  4. Set the userName and password and Click Sign-In.
  5. Make sure the browser navigated to the correct page.

Step 1: Launch Browser

'We will use SystemUtil.Run to launch our target browser
SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com/"

Step 2: Checking if the correct browser opened

The 2 new concepts in this step are:

  1. Reporter Object: This object is used to send individual reports to the test results. In other words, when the test ends, you can see the reported events in your Test results.
  2. ExitTest: A utility statement available to QTP that enables it to complete exit a Test. In other words, when this statement executes, the test execution ends.
If Browser( "title:=Welcome: Mercury Tours" ).Exist( 15 ) Then
   Reporter.ReportEvent micPass, "Step 1- Launch", "Correct browser was launched."
Else
   Reporter.ReportEvent micFail, "Step 1- Launch", "Browser failed to launch."
   ExitTest
End If

Step 3: Ensure the userName, password edits and the Sign-In button exist.

'Notice the use of the wildcard character below
If Browser("title:=Welcome:.*").Page("title:=Welcome.*").WebEdit("name:=userName").Exist(0) Then
   'set username
   If Browser("title:=Welcome:.*").Page("title:=Welcome.*").WebEdit("name:=password").Exist(0) Then
      'set password
      If Browser("title:=Welcome:.*").Page("title:=Welcome.*").Image("name:=login" ).Exist(0) Then
         'click button
      Else
         'report that Sign-In button was not found
      End If
   Else
      'report that the password edit was not found
   End If
Else
   'report that the userName edit was not found
End If

Step 4: Set the userName and password and Click Sign-In.

The following will complete the snippet above:

'Notice the use of the wildcard character below
With Browser("title:=Welcome:.*").Page("title:=Welcome.*")
   If .WebEdit("name:=userName").Exist(0) Then
      .WebEdit("name:=userName").Set "test"
      If .WebEdit("name:=password").Exist(0) Then
         .WebEdit("name:=password").Set "test"
         If .Image("name:=login" ).Exist(0) Then
            .Image("name:=login" ).Click
         Else
            Reporter.ReportEvent micFail, "Sign-In Button Error", "Button not found."
         End If
      Else
         Reporter.ReportEvent micFail, "Password Edit Error", "EditBox not found."
      End If
   Else
      Reporter.ReportEvent micFail, "UserName Edit Error", "EditBox not found."
   End If
End With

Step 5: Make sure the browser navigated to the correct page

'Synchronize with a browser
Browser( "title:=.*" ).Sync
 
'Wait 1 second for browser with "Find a Flight" title to exist
If Browser( "title:=Find a Flight.*" ).Exist( 1 ) Then
   Reporter.ReportEvent micPass, "Login", "Login successful"
Else
   Reporter.ReportEvent micFail, "Login", "Login failed"
End If
Putting it all together
'We will use SystemUtil.Run to launch our target browser
SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com/"
 
If Browser( "title:=Welcome: Mercury Tours" ).Exist( 15 ) Then
   Reporter.ReportEvent micPass, "Step 1- Launch", "Correct browser was launched."
Else
   Reporter.ReportEvent micFail, "Step 1- Launch", "Browser failed to launch."
   ExitTest
End If
 
'Notice the use of the wildcard character below
With Browser("title:=Welcome:.*").Page("title:=Welcome.*")
   If .WebEdit("name:=userName").Exist(0) Then
      .WebEdit("name:=userName").Set "test"
      If .WebEdit("name:=password").Exist(0) Then
         .WebEdit("name:=password").Set "test"
         If .Image("name:=login").Exist(0) Then
            .Image("name:=login").Click
         Else
            Reporter.ReportEvent micFail, "Sign-In Button Error", "Button not found."
         End If
      Else
         Reporter.ReportEvent micFail, "Password Edit Error", "EditBox not found."
      End If
   Else
      Reporter.ReportEvent micFail, "UserName Edit Error", "EditBox not found."
   End If
End With
 
Browser( "title:=.*Mercury.*" ).Sync
 
If Browser( "title:=Find a Flight.*" ).Exist( 1 ) Then
   Reporter.ReportEvent micPass, "Login", "Login successful"
Else
   Reporter.ReportEvent micFail, "Login", "Login failed"
End If

If you have any doubt in the content above, please feel free to post a comment about it. I hope this article helps understand further the principles of Descriptive Programming and using it in your everyday work.

Descriptive Programming Series

  1. Descriptive Programming (DP) Concepts – 1
  2. Descriptive Programming (DP) Concepts – 2 {Regular Expressions}
  3. Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}
  4. Descriptive Programming (DP) – 4 {Creating a Test Script)
Subscribe to Relevant Codes (by Anshoo Arora)
Hello! We're always posting interesting articles on Relevant Codes.
Why not subscribe so you don't miss out?

Leave a Comment

{ 114 comments… read them below or add one }

Anand Kumar February 6, 2013 at 2:31 am

Hello Team,
i have tried to customiize this code for gmail login but i am not able to do that it’s giving me error like”objects intilization failed” can you help me and tell me about the number which you given exist() somewhere you have given 15 and some here exist(0).

Thanks.
Anand Kumar

Reply

Anonymous December 4, 2012 at 1:30 pm

Hi Anshoo,

I am trying to identify Weblist object in my application using Desc Prog. While recording an object it recognizes the object with class:Weblist, Name, Html tag properties. When I use these properites in Desc prog it does not recognize. I tried to recognize the object with MicClass,Index, html tag properties combination but it does not work. In earlier build it used to recognize the object with its default property value only. But in the new build that property does not work as well.
Error is object not found…
Any Suggestions?

Set oPage=Browser(“B”).Page(“P”).Frame(“F”)
Set oWebList=Description.Create()
‘oWebList(“micClass”).Value=”WebList”
‘oWebList(“Html Tag”).Value=”SELECT”
‘oWebList(“Index”).Value=”0″
‘oWebList(“visible”).value = “True”
oWebList(“default value”).value= “Steady-State” ‘ — WEBLIST IS ONLY RECOGNIZED WITH THIS PROPERTY VIA DESCRIPTIVE PROGRRAMMIG. NO OTHER PROPERTY WORKS.
‘oWebList(“name”).value= “ctl00$m$g_8bd70945_d1ce_4425_b”
‘oWebList(“select type”).value= “ComboBox Select”

oPage.Weblist(oWebList).Select “Phase”

Set AllWebList=oPage.ChildObjects(oWebList)
MsgBox “AllWebList” & vbtab & AllWebList.Count

Thanks,
Sami

Reply

suvi October 21, 2012 at 7:07 am

hi can u please explain in detail each line

Reply

Anonymous October 13, 2012 at 4:50 pm

I am beginner in QTP and its a great startup thing. Thanks for putting it together.

Reply

monoshree kotal May 4, 2012 at 7:22 pm

Hi,

The contents are reALLY SIMPLE AND HELPFUL..It is very easy to understand. I am new to automation and your articles help me a lot.

Thanks

Reply

lakshmi February 9, 2012 at 7:13 am

hi,your work is really appreciable.It helps new learners a lot………….
I am new learner to qtp.Can u plz tell me the usage of below line u had used in above program.

Browser( “title:=.*Mercury.*” ).Sync

KINDLY HELP ME
THANKS.

Reply

Anshoo Arora February 13, 2012 at 12:19 pm

Lakshmi, the .Sync method “waits for the browser to complete the current navigation” (from QTP help).

Reply

Piyush February 3, 2012 at 4:28 am

Hi anshoo,
while adding ordinal identifier to the browser we used above like :
If Browser( “title:=Welcome: Mercury Tours”, “index:=0″ ).Exist( 15 ) Then
how wud I kno that index wud be equal to 0?
or if I wanted to use “creation time” then hw will I use it here?
please suggest.

Reply

Piyush February 3, 2012 at 4:00 am

Hi Anshoo,
In step2 we uses following code:
If Browser( “title:=Welcome: Mercury Tours” ).Exist( 15 ) Then
Reporter.ReportEvent micPass, “Step 1- Launch”, “Correct browser was launched.”
Else
Reporter.ReportEvent micFail, “Step 1- Launch”, “Browser failed to launch.”
ExitTest
End If
My question is what the use of “ExitTest” statement here as without using it we’ll get the test terminated itself bcoz there is no browser object open to perform next step.Please suggest.

Reply

Anshoo Arora February 13, 2012 at 12:02 pm

Piyush, in a larger context, we may have lots of code after this verification. If we do not exit here and move on to the next statement (speaking hypothetically ofcourse), we may error out. This is a way of avoiding such a situation.

Reply

Jaideep Patel January 19, 2012 at 12:37 am

Hi anshoo,

I have tried writing a DP script for a link with all the properties available when spied on, it does not work.
But if i add that object to the repository and then write the script, it works fine.
Why does this happen. Even if i use the same properties as used in OR, i’m still not able to write a DP script for it.

Thanks,

Jaideep Patel

Reply

Anshoo Arora February 13, 2012 at 11:05 am

Jaideep, the beauty of using DP is that you don’t have to write all the properties that you see from spy or the OR. You only need to write the property(ies) that are enough to uniquely identify the target object. If its a link, and if its seen only once in your application, you can use its innertext (or part of it using wildcards) to identify it. If it appears more than once, or you can use innertext along with Index.

Reply

Jaideep Patel February 13, 2012 at 11:10 pm

Hey Anshoo,

Thanks a lot for your help. I have one doubt.

In real time scenario which tpye of descriptive programming is used.
Ex: type 1
Browser(“name:=Google”).Page(“title:=name)

Ex: type 2
Dim btnGoogleSearch
set btnGoogleSearch=Description.create
btnGoogleSearch(“type”).value=”submit”
btnGoogleSearch(“type”).RegularExpression = False
btnGoogleSearch(“name”).value=”Google Search”
btnGoogleSearch(“html tag”).value=”INPUT”

Browser(“Browser”).Page(“Page”).Webbutton(btnGoogleSearch).Click

Out of these two types which is used in real time scenario. In my work palce we, iam using Type 1. Is that ok?

Reply

Jaideep Patel December 28, 2011 at 10:47 pm

Hi anshoo, i tried ur sloution. If i press the CTRL button i can see the object but i cannot spy it.. i can just perform the action but couldnt get the properties of the object.

Reply

Jaideep Patel December 28, 2011 at 10:35 pm

Thanks a lot anshoo… But i have another problem.

i have a webelement which has an innertext as “cilck to inster text”. when i click on it the webelement chaneges to web edit. how do i automate this…

Thanks,

Jaideep Patel

Reply

Anshoo Arora January 12, 2012 at 11:28 am

Jaideep: Can you please provide an example page where I can test this?

Reply

Jaideep Patel December 6, 2011 at 1:59 am

Hi anshoo,

I’m facing a problem to automate a web object which only becomes visible when we hover over it. i cannot use object spy to get the properties of that hidden object. How do i go about automating this.

Thank You

Jaideep Patel

Reply

Anshoo Arora December 27, 2011 at 6:59 am

Jaideep: You can use the CTRL key to hover the object then release CTRL to spy it..

Reply

Saumya November 25, 2011 at 6:12 pm

Hi Anshu,
I am a beginner in QTP and came through your forum.
It is absolutely fantastic.You have explained the things in the easiest possible way.Well done.

It to too late for a reply to the query,but since I could not find my answer for that in the above posts,just thought it’s worth posting it as somebody like me might struggle with the same.
My post is related to Akhilesh’s quey (post 9) and your reply(post 10).
I had the same issue which Akhilesh had while running the below script:
SystemUtil.Run “iexplore.exe”, “http://newtours.demoaut.com/”

If Browser( “title:=Welcome: Mercury Tours”, “index:=0″ ).Exist( 15 ) Then
Reporter.ReportEvent micPass, “Step 1- Launch”, “Correct browser was launched.”
Else
Reporter.ReportEvent micFail, “Step 1- Launch”, “Browser failed to launch.”
ExitTest
End If

The result was always :Browser failed to launch.

I then just replaced the identification for Browser
SystemUtil.Run “iexplore.exe”,”http://newtours.demoaut.com/”

If Browser(“title:=Welcome: Mercury Tours – Microsoft Internet Explorer”).Exist(15) Then
Reporter.ReportEvent micPass, “Step1″,”Browser opened”
Else
Reporter.ReportEvent micFail, “Step 2″,”Browser does not exist”
ExitTest
End if
and it worked.
I hope it would be helpful for a beginner like me.

Regards,
Saumya

Reply

Saumya November 25, 2011 at 6:14 pm

Apologies for using wrong spelling of your name Anshoo.

Reply

Anjali Vaswani August 18, 2011 at 6:57 am

Hi,

I’m new to Descriptive programming. I want to use checkpoints using Descriptive programming. Simple explain some simple examples of Text, Bitmap, Database, Text Area, Accessiblity and XML checkpoints. Your example of GUI checkpoint is very much clear to me .

Thanks,

Anjali vaswani

Reply

Subhashini August 1, 2011 at 7:23 am

Superb explanation…Nobody gives an explanation reg this to upto the mark.. Keep posting some new concepts(Eg: Switch case, do while, etc,..) of DP..So that many candidates can learn through it…

Reply

Uma May 23, 2011 at 5:14 am

Hi,
Its been a great work helping out with qtp . Only few weeks back i started with qtp now i have an idea about it. But to excel in qtp what are the necessary things to be done . How to practice on it . I don know how to develop logic thinking on DP as well.
Thank in advance

Reply

Anshoo Arora June 24, 2011 at 10:35 am

Uma: It will come by experience. Just Practice! Practice! Practice! :)

Reply

lalit February 24, 2011 at 11:31 pm

Dear Anshoo,

Thanks a lot for helping out QTP community.

Reply

Shubhang Jaiswal February 15, 2011 at 2:24 am

Hi Ashu,
This site is very informative, really appriciate the good work.
I am working with FSO, and have a little confusion in the below code.
**********************************************************************************

Set fso = createobject(“Scripting.FileSystemObject”)
filename=”c:\not_test.txt”
set MyFile=fso.createTextFile(filename)
MyFile.WriteLine(“shubhang Jaiswal is a good boy”)
MyFile.WriteLine(“shubhang Jaiswal is a good boy”)
MyFile.Close
Set MyFile=fso.opentextfile(filename)
do while MyFile.AtEndOfStream True
T=MyFile.readline
If instr(fso.opentextfile(filename).readall , “Shub”) >0 Then
msgbox “found”
strig=replace(fso.opentextfile(filename).readall,”Shub”,”sssssssssssssss”)
msgbox “replaced”
End If
Loop
MyFile.Close
*******************************************************************************************************
I am unable to replace the string using the above code.

Reply

Anshoo Arora February 19, 2011 at 7:21 am

The match is going to be case-sensitive. You’re writing “shubhang” but trying to replace “Shub”.

Reply

Madhurasmitha January 25, 2011 at 6:53 am

Hi Anshoo,

I have gone thru the site for Descriptive programming concepts , its very good for beingner like me to understand ,thanks very much.

I tried for our official website paypal.
when I am trying in the below method , its always failing.

‘Step 1 Check whether paypal apllication exists or not
SystemUtil.Run “iexplore.exe” , “https://www.paypal.com”
If Browser(“title:=Welcome*”).Page(“title:=Welcome – PayPal”).Exist(15) Then
Reporter.ReportEvent micPass,”Login page”,”Login Page exists”
Else
Reporter.ReportEvent micFail,”Login page”,”Login Page does not exists”
End If

So I tried another way like creating description for the browser and the Page , in this case it got suceeded
please find the code below

SystemUtil.Run “iexplore.exe”,”https://www.paypal.com”
‘ Creating Browser description
‘ “title:=Welcome – PayPal”
Set oPPBrowser = Description.Create
oPPBrowser( “title” ).value = “Welcome – PayPal”

‘ Creating Page description
‘ “title:=Welcome – PayPal”
Set oPPPage = Description.Create
oPPPage( “title” ).Value = “Welcome – PayPal”
If Browser(oPPBrowser).Page(oPPPage).Exist Then
Reporter.ReportEvent micPass,”Login”,”Page Exists”
Else
Reporter.ReportEvent micFail,”Login”,”Page not Exists”
End If
My question is
1.Why the first method is failing?
2.If I follow the second method then creating description for all the object is verify tedious , is there any way to create the description for all the objects?
3.when I am trying to spy any object on paypal application, it is showing the WebButton/WebEdit as WebElement only but if the record the steps then in OR i cloud see that it is storing WebButton/WebEdit and not as WebElement.
Cloud you please tell me any setting the i need to change to show the objects correct when using ObjectSpy?

Reply

Anshoo Arora January 25, 2011 at 9:34 am

Instead of:

If Browser("title:=Welcome*").Page("title:=Welcome – PayPal").Exist(15) Then

use:

If Browser("title:=Welcome.*").Page("title:=Welcome – PayPal").Exist(15) Then

Notice the dot-star (.*) instead of star (*).

Reply

Nalini December 30, 2010 at 7:51 am

Hi Anshoo Arora,

Thanks for all the knowledge, it is easy to understand.

All the best
Happy New year 2011 :)

Reply

Radhika August 26, 2010 at 10:28 am

Hi Anshoo,
Hope you are doing good.
Can you help me with environment variables in qtp? Actually i know what are those but can you give me one example using flight reservation like how it can be really used among different reusable actions.
I keep on reading on net that envt variables can be used among different reusable actions keeping its value same throughout.
Kindly help.
Thanks in advance
Radhika

Reply

Anshoo Arora September 2, 2010 at 7:35 am

Radhika,

Consider the below example:

'In [Action 1]
Dim sVariable
sVariable = "Text"

'In [Action 2]
MsgBox sVariable

Above, you will notice that sVariable is blank. This is because, all local variables have limited scope when it comes to actions. This means, a local variable within Action 1 cannot be seen or used by Action 2.

Now, consider the same scenario with Environment variables:

'In [Action 1]
Environment("sVariable") = "Text"

'In [Action 2]
MsgBox Environment.Value("sVariable")

Were you able to access the Environment variable in Action 2?

Reply

Monica August 5, 2010 at 6:14 am

i have written a code to select an element in the tree.Below mentioned is the code
Set MyBrowser= Description.Create()
MyBrowser(“title”).value= “A B A C U S – Recruitment – Windows Internet Explorer”

Set MyPage = Description.Create()
MyPage(“title”).value = “A B A C U S – Recruitment ”

Set MyFrame = Description.Create()
MyFrame(“title”).value = “Contents”

Set MyTree = Description.Create()
MyTree(“html id”).value = “TreeControl1_mtrvDsasList”
MyTree(“innertext”).value = “SR”

Browser(MyBrowser).Page(MyPage).Frame(MyFrame).WbfTreeView(“html id = TreeControl1_mtrvDsasList” , “innertext = SR” ).Select “SR”
Browser(MyBrowser).Page(MyPage).Frame(MyFrame).WbfTreeView(MyTree ).Select “SR”
it does not identify tree in Frame
It gives error as “Object doesn’t support this property or method: ‘Browser(…).Page(…).Frame(…).WbfTreeView’”
Can you pls tell me the possible reason for the same

Reply

Anshoo Arora August 5, 2010 at 2:18 pm

Monica,

Try this:

Browser("title:=A B A C U S – Recruitment.*").WpfTreeView("html id:=TreeControl1_mtrvDsasList").Select "SR"

Also, is this object a WbfTreeView instead of WpfTreeView?

Reply

QTPLearner July 14, 2010 at 9:30 am

Hi Anshoo,
How to validate date with the requirements like date should not be less than current date, should have day between 1 and 31, month between 1 and 12 and valid year starting with 20.
Kindly help.
Thanks

Reply

Anshoo Arora July 14, 2010 at 3:26 pm

This can be accomplished through the following VBScript functions/methods: Left, Right, Mid, DateDiff, Date, Day. You can choose a mix of them to get this task done.

If you need further assistance, I would strongly suggest you to download the first chapter (Basic VBScript) from Dani’s Book. It can be found here. Note: You must register with AdvancedQTP to view this material.

Reply

Vrinda May 18, 2010 at 9:39 am

Hi Anshoo,
I need your help to solve one problem. I am beginner with QTP and trying to write a script for following scenario.
With default flight application, started recording and entered invalid number in Tickets field. There was a pop-up error message which i handled using if loop. Tickets am entering using inputbox. What i want is that i can enter invalid ticket number any number of times i want and should continue.
When i enter ticket less then 10 it should continue further.

var1=inputbox(“Enter Tickets”)
Window(“Flight Reservation”).WinEdit(“Tickets:”).Set var1
‘When “Insert order” is clicked, error message is populated for Tickets.
Window(“Flight Reservation”).WinRadioButton(“Business”).Set
Window(“Flight Reservation”).WinButton(“Insert Order”).Click
If var1>10 Then
If Window(“Flight Reservation”).Dialog(“Flight Reservations”).Exist Then
Window(“Flight Reservation”).Dialog(“Flight Reservations”).WinButton(“OK”).Click
Window(“Flight Reservation”).WinRadioButton(“Business”).Set
Window(“Flight Reservation”).WinButton(“Insert Order”).Click
End if
End If
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;New Order”

Kindly help.
Vrinda

Reply

Anshoo Arora May 26, 2010 at 8:11 am

That part of the loop can be controlled by the following:

Do 
	var = InputBox("Enter Tickets")
	If var < 10 And var > 0 Then Exit Do
Loop

Reply

Radha April 30, 2010 at 5:34 am

Hi Anshoo,

Good post on DP. I have prepared one script which validates username and password field using mercury’s default website. Can you please see and let me know if m going on correct path?

Script is as below:

Systemutil.Run "iexplore", "http://newtours.demount.com/"

Browser("").Page("").WebEdit("Username").set "Parameterized values as shown in table below"
Browser("").Page("").WebEdit("Password").set "Parameterized values as shown in table below"

'Usign GetRoProperty to get value from table.
Uname = Browser("").Page("").WebEdit("Username").GetRoProperty("value")
Password = Browser("").Page("").WebEdit("Password").GetRoProperty("value")

Browser("").Page("").Image("Sing in").click 48,39

if Uname ="" and Password = "" then
  msgbox "Please enter Username and Password")

elseif Uname  'valid username' or Password 'valid Password' then
  msgbox "Username or Password are invalid"

elseif Uname = 'valid' and Password = 'valid' then
  msgbox "Login successful"

End if

Table:

Username	Password
1. abc	abc(invalid)
2. Blank	Blank
3. Valid	valid

Thanks,
Radha

Reply

Anshoo Arora May 2, 2010 at 12:39 pm

After the following lines are executed:

Browser("").Page("").WebEdit("Username").set "Parameterized values as shown in table below"
Browser("").Page("").WebEdit("Password").set "Parameterized values as shown in table below"

As long as the maxLength property of the WebEdits is not 0, something will definitely be set. Therefore, the following statement:

if Uname ="" and Password = "" then

can only be true if nothing was set, or the properties supplied were incorrect. For the latter, its better to use .Exist instead. Don’t think I understand the following statement though:

elseif Uname  'valid username' or Password 'valid Password' then
  msgbox "Username or Password are invalid"

Reply

Neelakantan G S April 14, 2010 at 1:30 am

HI Anshoo,

I like the way you explain the DP. You broke my bad assumptions on descriptive programming.

Cheers,
Neelakantan G S

Reply

Balaji April 12, 2010 at 7:06 am

Hi,
I have webtable which size 7 column and 4 rows.
Each row i have set of webelements.
I am using checkpoints for checking whether the webelements are there ?
My problem is that , webelement property of one row is similar to other , so it says multiple objects found with the same property.
could you please tell me whether ordianl identifier can use in the checkpoint?
if so please let me konw?

Reply

Anshoo Arora April 13, 2010 at 1:56 pm

Balaji, why don’t you use the GetCellData method of the WebTable instead? A WebElement is generally some text in a Web Application, and using GetCellData, you will be able to retrieve that test regardless of how many times it appears in your application.

Reply

Achu February 19, 2010 at 3:11 am

Hi Anshoo,

I don’t know exactly but I think ‘Flight Reservation Table’ is also a WinList View object.Is it?

Thanks&Regards
achu

Reply

Anshoo Arora April 13, 2010 at 1:55 pm

Its a Notepad window, correct? Shouldn’t be a WinList object, then.

Reply

Achu February 19, 2010 at 3:05 am

Hi Anshoo,
Thank you very much for the reply.

Currently I had one application with me,That is “Scan to Email Setup”wizard.
I think in Medical field applications ,we can see such type of schenario.
I ‘m not remembering any other application,
I try to post a screenshot of the application,but I can’t.
I think if that is possible the scenario will be very easy to understand.
I will try once again and will get back to you soon.

Thanks&Regards
dhanya

Reply

Anshoo Arora February 19, 2010 at 10:31 am

Achu,

I found the code I had written for my application:

sText = "TestTOFind"
	
'Insert Dialog description below
With Dialog("")

	'Get total number of items in the WinListView
	iItemsCnt = .WinListView("window id:=1").GetItemsCount
	
	'Start searching from the most recent (bottom-most) item to the oldest item
	For ix = iItemsCnt - 1 to 1 Step - 1
		
		'Activate the row
		.WinListView("window id:=1").Activate ix
		
		If Dialog("", "regexpwndtitle:=" & sText).Exist(1) Then
			Set oWScript = CreateObject("WScript.Shell")
			oWScript.SendKeys "{ENTER}"
			Exit For
		End If
		
	Next

End With

Its very similar to what you have there..

Reply

Achu February 18, 2010 at 5:56 am

Hi Anshoo,

How can we click an item in a listbox using Dp?

The dialog box contains a listbox.In that there are 4 columns and rows.
I had to click in the 3rd column’s item.

I had searched for the script in many sites.I didn’t get any answer.
Finally I had done low level recording.From that I get the item’s positon’s value,but it is not the exact ‘x & y’ value.
And I had put that value in Script,it works.

My code is like this
“Dialog(“text:=HP Scan to E-mail Setup Wizard”).WinListView(“window id:=1093″).Click 454,27
Dialog(“text:=HP Scan to E-mail Setup Wizard”).Dialog(“text:Dialog”).WinButton(“text:Show Send Log”).Click”

But I know,it is depend upon the machine.

So can you suggest any other alternative method for doing that…

thanks
achu

Reply

Anshoo Arora February 19, 2010 at 2:21 am

Hi Achu,

It might be hard for me to reproduce this scenario, but from what I remember about WinListViews, there is a technique that can enable you to traverse through each row depending upon the column of focus. I don’t quite remember how I did it before.. I will try to find an application with such an object and only then would I be able to provide with a solution.

Achu, is there any application that you could suggest that would enable me to have access to a WinListView object?

Reply

Achu February 18, 2010 at 5:21 am

Hi Anshoo,

Thanks a lot for such a wonderful discription on descriptive programming in a very easy manner.
Your explanation to questions asked was simply super.

Reply

Anshoo Arora February 19, 2010 at 1:17 am

Thank you, Achu :)

Reply

Renu Bajaj February 14, 2010 at 7:20 am

Hi Anshoo,

You can send anwser in this site itself so other can also take advantage.

Bye
Renu

Reply

Renu Bajaj February 14, 2010 at 7:13 am

Hi Anshoo,
Thanks for your prompt reply. can you pls give me the same kind of example for the windows application(Flight) so i’ll get idea how these windows objects works and what is the hierarchy of objects.

Thanks in advance
Renu :-)

Reply

Anshoo Arora February 15, 2010 at 12:39 pm

Okay, Renu. I will try to post an article soon on either the application you mentioned or ways of automating a Web Application, mainly GMail. There is, however, an article on automation Windows Calculator on Relevant Codes which you might find helpful.

Reply

Renu Bajaj February 11, 2010 at 1:18 pm

Thanks a lot for such a wonderful discription on descriptive programming in a very easy manner. Anshoo, I ve 6 yrs for exp in programming in VB and .Net but i m new in testing especially in QTP programming. pls help me to learn it in a fast mode with some great example of code of descriptive programming.

Thanks in Advance
Renu

Reply

Anshoo Arora February 11, 2010 at 2:19 pm

Hi Renu,

What you see in these articles on RelevantCodes and on other websites detail pretty much everything that is relevant to know about Descriptive Programming. You have an excellent background for this field, and there are a handful of people with strong development background and I am sure you’ll do fantastic work.

Good luck! :)

Reply

Puneet Varma January 25, 2010 at 1:59 pm

Hi,

When i input a new user then the reporter.event should display the new user. I have indicated &username which indicated in my script. I know I am definitely doing something wrong. Any help will greatly appreciate it.

Dim username
username = NewUser = ‘provider’

SwfWindow(“HA – You are currently”).SwfWindow(“Add User”).Dialog(“HA – [Acknowledgement]“).Exist Then
Reporter.ReportEvent micPass, “Verify the user has been added”, “The ” &username “successfully has been added”
SwfWindow(“HA – You are currently”).SwfWindow(“Add User”).Dialog(“HA – [Acknowledgement]“).WinButton(“OK”).Click
Exit For

Reply

Anshoo Arora January 26, 2010 at 11:04 am

Hi Puneet,

The below statement is invalid:

username = NewUser = ‘provider’

What the above statement means is, username is a boolean value that evaluates NewUser = 'Provider'. It should be this instead:

userName = NewUser
userName = "provider"

The rest of the code should be this:

If SwfWindow("HA – You are currently").SwfWindow("Add User").Dialog("HA – [Acknowledgement]").Exist Then
	Reporter.ReportEvent micPass, "Verify the user has been added", "The " &username "successfully has been added"
	SwfWindow("HA – You are currently").SwfWindow("Add User").Dialog("HA – [Acknowledgement]").WinButton("OK").Click
End If

Reply

Raju N November 26, 2009 at 11:25 pm

Hi Anshoo,
Thank you so much for your kind help.Whenever i posted question,you replied very soon.really i am proud of you sir

Reply

Raju N November 26, 2009 at 5:45 am

HI Anshoo,
I am working in MNC.i got chance to work on the QTP.COuld you plese tell me how to prepare framework for an any realtime appliations.is there any standard to prepare it.Please give me an idea reg this.this will be a great if you explain this with an example.

Thanks,
Raju N

Reply

Anshoo Arora November 26, 2009 at 11:04 am

Hi Raju,

Please read the following document which describes different types of frameworks, with examples. My framework will be available in a few weeks, and I think that may serve as an example you are looking for. Its a conceptual framework, meaning, it contains concepts from several different frameworks and methodologies which may help people new to framework development understand the principles behind creating a good architecture.

Good luck :)

Reply

Satishkumar Dega November 25, 2009 at 12:07 am

Hi Anshoo,
I have one doubt can u clarify that one
The problem is I recoreded one test using mecury site and prameterize that test .
In data table global sheet I mention two columns like Dept_City and Arrival_City
In that I prameterise that one with two different values like
1.London to Paris
2.Portland to New York
In that I put one text checkpoint in the Select a Flight: Mercury page in the above values
First Iselected the London right click select the insert text check point it will open text chepoint poperties in
Check that London to is displayed between DEPART and Paris.
1.London I am selecting parameter option I map that one to Dept_City in the datatable it is displying in this way
Check that is displayed between DEPART and Paris.
2. After that I selected text after I mapped the paris value to Arrival_City in the datatable it is displaying like this way
Check that is displayed between DEPART and .
In this case it is working fine in both two ierations but I am puting one text checkpoint in the arrival checking at the time I am getting error
Same steps I followed
I selected Paris rigt click and puting insert text check point it is displying in this way
Check that Paris is displayed between New York to and 12/15/2009
after that I select parameter option I meped the paris to Arrival_City in the datatable it is displayong like this way
Check that is displayed between New York to and 12/15/2009.
After that I selected text before I maped the New york to in the Dept_city in the data table it is displaying like this way
Check that is displayed between and 12/15/2009.
Here the problem is in last postion it is displaying date like “12/15/2009″ the date is same in two ietarations there is no problem if the date is changed at the time the second ietaration is failed i did not under stand the proble wt is the problem can u explain this
the blelow is failed in second ietaration for ur reference
Text Checkpoint: captured “” between Portland and 12/15/2009 , expected “New york”
Match case: OFF
Exact match: OFF
Ignore spaces: ON

Reply

Anshoo Arora November 26, 2009 at 11:02 am

Hi Satishkumar,

As you said, if the date changes (which it will), your test will fail. Such situations are good candidates for regular expressions or parameterization. What you would need to do here is, instead of using a static date for your CheckPoint, you would have to use a dynamic date. Now, this date value can come from the DataTable, or it can be a Regular Expression. Can you try either of the 2 options and see which one works better? If you have any questions, please feel free to ask.

Reply

Satishkumar Dega November 23, 2009 at 5:18 am

Hi Anshoo,
How to import files and how to call the functions in the QTP.
can u give me one sample example and explain the things plz

Reply

Anshoo Arora November 23, 2009 at 10:21 am

Importing sheets to QTP are quite simple and this is how it can be done:

DataTable.ImportSheet(FileName, SheetSource, SheetDest) 

Example:

DataTable.ImportSheet "C:\MyFile.xls", "Sheet1", "Action1" 

As for functions, they can be called in QTP the exact same way as they’re called in VBScript.

Reply

raju November 23, 2009 at 2:57 am

HI,
Could you pls tell me How to import data from the OpenOffice Spreadsheet in QTP

Reply

Anshoo Arora November 23, 2009 at 10:17 am

Hi Raju,

I haven’t work on OpenOffice with either VBScript or QTP, so I am not sure how it is going to work. This post outlines several ways OpenOffice can work with VB and you can modify the code for your use.

I am not sure how you can use it to import data to QTP’s DataTable though. I doubt this will be possible.

Reply

Radhika November 4, 2009 at 1:56 pm

Hi Anshoo,

In the above example we have checked the availability of text boxes and buttons in login page and then entering values to login and move on to the next page.
Does inserting of “Checkpoints” is applicable here?
For example, inserting 1) standard checkpoint for “Login” and “Cancel” button, 2) Image checkpoint for the flight image…etc (If applicable, can you please give me the exact location in script where i can insert checkpoints)
OR
since the buttons are always enabled there is no need to check and so no checkpoint and same for image.

Please guide…
Thanks,
Radhika

Reply

Anshoo Arora November 4, 2009 at 2:14 pm

Hi Radhika,

I hope you are doing well.

What you see in this example, which checks the existence of the WebEdit before entering a value is nothing but a (custom) Checkpoint. You can do the same with a Standard Checkpoint as well, but I find custom checkpoints easily written and highly manageable.

For example, inserting 1) standard checkpoint for “Login” and “Cancel” button, 2) Image checkpoint for the flight image…etc (If applicable, can you please give me the exact location in script where i can insert checkpoints)

Its hard to describe an exact location; numerous validations performed through each script. To give you an example though, when you launch an application, you can check whether all the mandatory objects exist, or not. If not, the test fails. If they do, you proceed to the next step.

Let’s take a Cart Checkpoint process for example too. When you click “Checkout” you may expect a customized message for you, the amount of purchase, your Card details, your address etc. You can verify all of this, to make sure the application’s behavior is as expected. You can choose to create Standard Checkpoints, or custom, as long as they verify correct entities within the application.

since the buttons are always enabled there is no need to check and so no checkpoint and same for image.

That’s quite true. But, a good script doesn’t trust the application completely and performs all necessary validations. You never know when one of your validation catches something that may be extremely valuable to your team. :)

Reply

Radhika October 29, 2009 at 8:02 am

Hi Ansoo,

I will definitely go through the document you have mentioned….also you have given a good start with such a simple example….

Thanks,
Radhika

Reply

Anshoo Arora October 29, 2009 at 10:23 am

Sounds great!! I wasn’t sure if you would find that helpful.

But, I’m glad you did. :)

Reply

Radhika October 28, 2009 at 10:18 am

Anshoo,

Can you please explain the difference between Data driven testing and keyword driven testing?
As per my understanding, Data driven is nothing but parameterization…ie using different input values for same test case. Am i correct?
And for Keyword driven am not clear….
Kindly help.
Radhika

Reply

Anshoo Arora October 28, 2009 at 11:06 am

Hi Radhika,

As per my understanding, Data driven is nothing but parameterization…ie using different input values for same test case. Am i correct?

Correct. It is parameterization off data-pools on potentially a large scale. However, apart from only retrieving the Input values, a data-driven framework also retrieves the Output values for verifications. Lots of variables here.

And for Keyword driven am not clear

This type of framework runs on “keywords” that represent a logical entity on the code level. For example:

Keyword Argument Output
LaunchApp http://google.com
SearchText QTP Automation
CloseApp http://google.com

All the outputs will be available after the script has been run.

Of course, the above table is just an example. The framework itself will be quite large and it can have provision for more keywords, depending on the type of application.

I would also recommend you to refer to this document by Carl Nagle which provides a brief overview of different sorts of frameworks. Bullets 1.2.1 and 1.2.2 discuss Data-Driven and Keyword-Driven frameworks. This is also an excellent source.

I hope this helps..

Reply

Satishkumar Dega October 28, 2009 at 6:41 am

Hi Anshoo,
Today I have complete one test using sample mecury site(recording/playback).In that test I have put one check point like (Insert Text check point)
Flight Confirmation # 2009-10-28052358 this page will come at last fight confrimation page I have put one check point in the (2009) .In that I have mention the using regular expression like this [0-2][0-9][0-9][0-9].After the save the test and run the script it is failing the test where ever I put checkpoint it is failing.
I saw the results is displaing like this
Text Checkpoint: captured “” between Flight Confirmation # and -10-28072003 , expected “[0-2]|[0-9]|[0-9]|[0-9]”
Regular Expression : ON
Match case: OFF could u please help me this one

Reply

Anshoo Arora October 28, 2009 at 10:05 am

I think a good Regular Expression considering the year will change every year, and the last part seems dynamic, you can use this:

20\d\d-10-\d+

Or, if you would like to test only 2009 dates, you can use this:

2009-10-\d+

Or, if you would like to match any such number with the same pattern, you can simply use this:

\d+-\d+-\d+

There are several ways you can use the approaches above. But, I would recommend a good walkthrough on Regular Expressions first – the knowledge you gain will be very useful to you.

Reply

Satishkumar Dega October 28, 2009 at 4:26 am

Hi,
I have one doubt regrading regular expression.
I useed the HP/Mercury Demo Website for this example.In that site I have selected in flight conformation page I want test one number like Flight Confirmation # 2009-10-28052358 I want check the 2009 using regular expression How I will check this plz this is very urgent please help me.
Is there any way test that one.

Reply

Anshoo Arora October 28, 2009 at 10:01 am

For 2009:

This will match any year that begins with 20. Example: 2000, 2010, 2099 etc:

20\d\d 

This will match any year that begins with 200. Example: 2000, 2001, 2009 etc:

200\d

You can also refer to this great website for more information on Regular Expressions.

Reply

Satishkumar Dega October 27, 2009 at 1:15 am

Hi,
My name is Satish kumar I am new to the testing .I am learing QTP I want to know the when we write descriptive programing can you give me one real time example and explain the each step this very urgent for me.Could you send any QTP documnets to my mail id satishkumardega@gmail.com

Reply

Anshoo Arora October 27, 2009 at 8:20 am

Hi Satishkumar,

I think nowdays, Descriptive Programming has become the technique by choice of many automation developers. Most of them come from a Record/Playback (including myself) background and after realizing its short-comings and the great flexibility and control you get with Descriptive Programming, I guess they all just stayed.

To go over all the short-comings and benefits in a single reply might be too overwhelming for the both of us. I wrote an article a while back that compares Descriptive Programming with Object Repository and I feel it may be able to answer a few of your questions. Please go over this topic and one or two in the Descriptive Programming Category and if you have any doubts, we will work together to clarify them.

Reply

Radhika October 21, 2009 at 11:39 am

Hi Anshoo,

Very good article..I am beginner with QTP and referring your blog for reference. It helped me a lot…hope to see some more good examples like this using checkpoints and parameterization…. :)

Thanks,
Radhika

Reply

Anshoo Arora October 21, 2009 at 5:41 pm

This one is for you Radhika: QuickTest’s Custom CheckPoints and Beyond.

:)

Reply

Brian October 12, 2009 at 12:44 pm

Anshoo,

First, very nice articles! They are very helpful and you do a great job capturing the key points of DP.

You mentioned in one of your earlier articles that you do not agree with the concept of using DP to create object descriptions and then using those descriptions in later scripts/functions as shortcuts. I was just curious as to your reasoning here? I’m working on an automation framework that is leveraging DP to create an application map of the AUT by creating multiple object descriptions for all of the test objects that we are concerned with in the framework. In later scripts and functions the object descriptions will be referenced instead of using the DP descriptions to locate the test object.

I’m following this approach to compartmentalize the application map of the GUI components so that later, when the application does change, I can just update the application mapper rather then going through all the test scripts and updating the parameter values in the DP calls.

I’d appreciate your opinion regarding this approach. If you know of any limitations that will cause this framework to be unmanageable, I’d be in your debt if you identify it early.

Thanks in advance!
Brian

Reply

Anshoo Arora October 12, 2009 at 5:34 pm

You mentioned in one of your earlier articles that you do not agree with the concept of using DP to create object descriptions and then using those descriptions in later scripts/functions as shortcuts.

I think I wrote, “The only time I use this technique is to retrieve object collections through ChildObjects”. But, you raise an excellent point and I think I must revisit my article and provide some information for the readers. Thank you.

To answer your question, I don’t use Description Object much is because in large projects, when you have thousands of lines of code, it can sometime become tedious to refer to Description Objects by continuously scrolling up and down to find what each description says. A better technique, in my opinion, is to have a single Dictionary that contains all these descriptions in a separate library (see below). But, at the same time, I also believe that a lot of our work circles around what the preference is of the automation developer. So, what works well for me, may not work well for someone else on my team.

I’m working on an automation framework that is leveraging DP to create an application map of the AUT by creating multiple object descriptions for all of the test objects that we are concerned with in the framework.

What you’re doing is perfectly fine, and I’ve been on projects where this methodology has been followed. However, the key here is that, your libraries must be organized in a way that finding what you’re looking for must be rapid and must not take a lot of your time. Again, I haven’t used this approach myself in the past, and I’m clearly not knowledgeable to provide you a good explanation on the use of this technique.

If you know of any limitations that will cause this framework to be unmanageable, I’d be in your debt if you identify it early.

As I said, I’m not entirely sure and my knowledge on this topic prevents me from extending anything to you that might cause you many difficulties in the future. However, I can show you a few concepts that can be used to create automation test suites where time and maintainability are of great importance:

1. Using Classes to keep all your functionality intact.

2. Creating a GUI Layer of Classes – this is closely related to what you want to achieve, but instead of keeping all descriptions in a single library, this concept shows how to keep all descriptions under a single class. However, a dictionary on a library level can be created that stores all descriptions:

Set m_htContext = CreateObject("Scripting.Dictionary")
With m_htContext
                .Add "Username", Browser("LoginPage").Page("LoginPage").WebEdit("name:=userName")
                .Add "Password", Browser("LoginPage").Page("LoginPage").WebEdit("name:=Password")
End With

The advantage is, you’re looking for an object under the same tree, instead of created multiple tree-levels.

3. Another good approach is to load all your descriptions in a Table. In my new article Creating a Test Data Dictionary, I have shown a way how data at runtime can created in less than a second and used in any sort of a framework with ease. A similar approach can be used with Object Descriptions.

In conclusion, and this is entirely dependent on personal preferences, it depends how automation developer likes to maintain their object collections. If you ask me, I like keeping descriptions in Tables instead of libraries. However, that is also because I am a consultant and being on a project more than 3 months is a rarity. Putting all descriptions in Tables give my clients the ease to update descriptions as they like, without opening function libraries which they may not prefer.

Brian, I am not sure if I gave you a satisfactory answer, but I hope you find a solution soon. If you have any doubts in any of the concepts mentioned here, please let me know and I will try my best to help you.

Reply

akhilesh October 3, 2009 at 1:45 am

Hi Anshoo,

I follow your suggestion, Script ran successfully without any interruption and got the positive out come as usual. But antagonistically, I got the result with “Browser fail to launched” again.

Thank you for well explained ‘ExitTest’ concept.

Reply

Anshoo Arora October 3, 2009 at 8:59 am

Akhilesh, that’s quite strange. I just ran the script and it worked fine:

SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com/"

If Browser( "title:=Welcome: Mercury Tours", "index:=0" ).Exist( 15 ) Then
	Reporter.ReportEvent micPass, "Step 1- Launch", "Correct browser was launched."
Else
	Reporter.ReportEvent micFail, "Step 1- Launch", "Browser failed to launch."
	ExitTest
End If

I was able to create a video of the entire process as well: Click here to watch the video.

Okay, let’s start from the beginning and analyze where the error occurred.

1. Do you have the Web add-in selected?
2. When you ran the script, were there any other browsers with the title (Welcome: Mercury Tours) open?
3. What version of QTP are you using, and what is your default browser (IE, FireFox etc.)?
4. When you open a browser, are you able to record successfully on it? I mean, do you get the correct hierarchy in Expert-View mode:

Browser("").Page("").WebEdit("").Set ""

I really hope we can get this issue resolved, because without it, it may not be possible to create any other scripts..

Reply

akhilesh October 1, 2009 at 12:50 am

Hello Anshoo,

Things you explained and the way of explaining both are very good. I have observed one issue. I am using 9.0 version, and on running first part (step I and step II combindly) of the code which about to launch the browser & checking the correct browser is opened. All the time I got the result as ‘failed’.

The step, where I got failed the result is:

The step name: Step 1- Launch

Object Details Result Time
Step-Launch Browser failed to launch Failed 10:30

Though, browser opened successfully and given link and page of flight also dispalyed on the browser.
What does this error means? Kindly explain.

How does ‘ExitTest’ make effect on result. I removed ‘ExistTest’ and ran the script, no difference is showing at all.

with the best wishes,

Thank you,

Reply

Anshoo Arora October 1, 2009 at 6:41 pm

Hi Akhilesh,

Please see my notes below:

on running first part (step I and step II combindly) of the code which about to launch the browser & checking the correct browser is opened. All the time I got the result as ‘failed’.

I think there may be more than 1 browser open with the same title. If that is the case, please add an ordinal identifier, so QTP does not get confused with which browser we’re working with:

If Browser( "title:=Welcome: Mercury Tours", "index:=0" ).Exist( 15 ) Then

Also, I created this demo for only 1 Browser open, so could you please try to execute it with a single open browser and let me know if the same issue re-occurs?

How does ‘ExitTest’ make effect on result. I removed ‘ExistTest’ and ran the script, no difference is showing at all.

As the name suggests, when ExitTest executes, the test ends. In other words, it supplies us with a sort of error handling where if things go extremely wrong, we can simply Exit the test, and stop test execution.

Reply

saurabh September 29, 2009 at 7:26 am

Anshoo,

Really, an appreciating effort, kudos..best of luck for every moment. appear like kind of mile stone work you have done.

Great,

Reply

Anshoo Arora September 29, 2009 at 6:54 pm

Thank you so much for your kind words. :)

Reply

saurabh September 29, 2009 at 7:25 am

Anshoo,

here you have use image inplace of webbutton, can you let us why is this so? and how would we recognize that give button is image or not, specially when we are working on dp and can not take help of object spy?

TY in advance

Reply

Anshoo Arora September 29, 2009 at 6:56 pm

Saurabh,

A key difference to identify an image from a button is that when you right click on them, you will have an option to save the image, whereas for the button, you won’t :)

Apart from using Object Spy, you can use the IE Developer’s Toolbar, DebugBar etc. They also list all the properties of the object, but I don’t quite remember if they mention the ClassName like QTP does. You might have to make meaning out of the object tags instead.

Reply

Raj kumar September 21, 2009 at 8:20 am

Please post the DP for Repository in next phase

Reply

Anshoo Arora September 21, 2009 at 7:48 pm

Raj,

DP for Repository? Can you please clarify? Thanks!

Reply

Satishkumar Dega October 27, 2009 at 11:40 pm

Thanx for giving reply first I will go throgh the what ever u mention topics in tha above section.
After that I wll ask u .

Reply

Anshoo Arora October 28, 2009 at 10:06 am

That sounds good!! :)

Reply

Satishkumar Dega October 29, 2009 at 12:13 am

Hi did not under stand the regular expression concept canu you give me an over view on that.
When we will use the regular expression concept how to use that one.
Could you give one example and explain the example.

Reply

Satishkumar Dega October 30, 2009 at 2:20 am

Hi Anshoo,
I went through the regularexpression articles I got an idea.But still I have one doubt that is I try to record on test and play the script in the final page I have select a particular number and I put one Insert text check point I ran the script but it is failing.
Ex : Flight Confirmation # 2009-10-30025808 2009-10-30 02:58:08.0 U know the last page of flight confrimation page this text will come but I select (025808) this thing I have try to put one check point but QTp tool is identifying like this
Check that 0258 is displayed between Flight Confirmation # 2009-10-30 and 53 2009-10-.last digts are dynamically changes but QTP identify the only select the only 4 dights at the time 2 numbers are not select at the time failing If I select all the data like (Flight Confirmation # 2009-10-30025808 2009-10-30 02:58:08.0) at the time I have put check point and I mention regular expression what ever u mention aboe article its working fine I need to check in a particular thing using regular expression is it possible can u explain the things plz.
I really thanx a lot for u giving good support for me.

Reply

Anshoo Arora October 29, 2009 at 10:09 am

Hi Satish,

Please go through this article on Regular Expressions. You should be able to find some information on the use of Regular Expressions when using QTP. If you have any questions after having read the article, please feel free to ask. However, there is ample detail on the use of both WildCards and Regex formats there you get you started.

You can also see this article, which also covers a few basics on this topic.

I know I am always directing you to different sources, but there has been so much already said about these topics, which even if I try won’t do as good of a job in explaining everything in this small space :)

Reply

Anshoo Arora October 30, 2009 at 8:33 am

At the Flight Confirmation page:

1. Start Recording if QTP is not in Record mode
2. Insert -> Checkpoint -> Standard Checkpoint
3. Click the “Flight Confirmation XXXX-XX-XXXXXXXX” WebElement
3. Object Selection Window -> Makes sure WebElement shows up as the bottom-most object
5. Click OK
6. Uncheck “HTML TAG” if its checked. Only “InnerText” should be selected.
7. Click on the “InnerText” Row
8. Besides the Constant Textbox, there is a button to the right. Click that.
9. A window titled “Constant Value Options” will show up.
10. Replace “Flight Confirmation XXXX-XX-XXXXXXXX” with this “(19|20)\d\d-\d\d-\d+” and check “Regular Expression”
11. Click OK
12. Click OK to close the Checkpoint Properties Window
13. Stop Recording
14. Once you’re done, you will have the following statement in QTP:

Browser("Flight Confirmation: Mercury").Page("Flight Confirmation: Mercury")_
    .WebElement("Flight Confirmation #")_
    .Check CheckPoint("Flight Confirmation # 2009-10-30092408")

15. Execute your code now and check the results.

Note: You will have to follow the same process for the WebElement object because when its recorded, its recorded to match with the static string. You will have to replace it with a Regular Expression shown above.

Reply

Satishkumar Dega November 3, 2009 at 1:02 am

Hi Anshoo,
I tryed what ever u mention the steps but it is failing the test.for ur reference I am sending my test
why this is failing can u check it and let me know.

Browser(“Welcome: Mercury Tours”).Page(“Welcome: Mercury Tours”).WebEdit(“userName”).Set “satishdega”
Browser(“Welcome: Mercury Tours”).Page(“Welcome: Mercury Tours”).WebEdit(“password”).SetSecure “4aefbf53f0eb009d5a950f455b4090533e17″
Browser(“Welcome: Mercury Tours”).Page(“Welcome: Mercury Tours”).Image(“Sign-In”).Click 29,5
Browser(“Welcome: Mercury Tours”).Page(“Find a Flight: Mercury”).Image(“findFlights”).Click 38,10
Browser(“Welcome: Mercury Tours”).Page(“Select a Flight: Mercury”).Image(“reserveFlights”).Click 36,6
Browser(“Welcome: Mercury Tours”).Page(“Book a Flight: Mercury”).Image(“buyFlights”).Click 43,10
Browser(“Welcome: Mercury Tours”).Page(“Flight Confirmation: Mercury”).WebElement(“Flight Confirmation #”).Check CheckPoint(“Flight Confirmation # 2009-11-03002139″).

Reply

Anshoo Arora November 3, 2009 at 11:44 am

Hi Satish,

I think it will be easier to demonstrate it through Descriptive Programming:

Browser("title:=Welcome.*").WebEdit("name:=userName").Set "test"
Browser("title:=Welcome.*").WebEdit("name:=password").Set "test"
Browser("title:=Welcome.*").Image("name:=login").Click
Browser("title:=Find a Flight.*").Image("name:=findFlights").Click
Browser("title:=Select a Flight.*").Image("name:=reserveFlights").Click
Browser("title:=Book a Flight.*").Image("name:=buyFlights").Click
'Solution 1
MsgBox Browser("title:=.*Confirmation.*")_
    .WebElement("innertext:=.*(19|20)\d\d-\d\d-\d+", "index:=0")_
    .GetROProperty("innertext")
'Solution 2
MsgBox Browser("title:=.*Confirmation.*")_
    .WebElement("innertext:=.*\d+-\d\d-\d+", "index:=0").GetROProperty("innertext")

Please test the above code and let me know if you have any questions..

PS. You can use the same Regular Expression with Record/Playback as well.

Reply

Satishkumar Dega November 19, 2009 at 2:01 am

Hi Anshooo,
The above code is working fine in both Solution 1 and Solution 2.
Thanks for giving good Solution.

Reply

Anshoo Arora November 19, 2009 at 12:12 pm

Most welcome :)

Reply

Satishkumar Dega November 27, 2009 at 12:07 am

Hi Anshoo,
I tried that one but it failing I din’t understand can you give me one example and explain that one plz

Reply

Anshoo Arora November 27, 2009 at 11:16 am

At the flight confirmation page, you can use the following regex string for the WebElement to identify it:

Browser("title:=Flight.*").WebElement("innertext:=\D+ to \D+", "index:=0").Highlight
Browser("title:=Flight.*").WebElement("innertext:=\D+ to \D+", "index:=1").Highlight

If you would like to retrieve the text:

MsgBox Browser("title:=Flight.*").WebElement("innertext:=\D+ to \D+", "index:=0")_
    .GetROProperty("innertext")
MsgBox Browser("title:=Flight.*").WebElement("innertext:=\D+ to \D+", "index:=1")_
    .GetROProperty("innertext")

This would be custom checkpoint though. However, you can use the exact same regex to identify the text in the flight confirmation page through Object Repository also.

Reply

Anonymous February 22, 2010 at 10:51 pm

Anshoo,

Thank you very much for the reply.I am sorry for the late reply.
I will implement ur code,in my code and will tell the result.
Thans once again.

Thanks&Regards
achu

Reply

Achu February 23, 2010 at 11:47 pm

Hi Anshoo

The code doesn’t work.I implement the code but it doesn’t work.
“Enter” through keyboard is not possible.
Only Mouse click is possible and it is only possible to the 3rd column in the row(0).
If we click any where else in the row,it will not work.
The new window will come only if we click the 3rd column.
If i can post any screenshot here,I will post my application’s screenshot,so that u can understand better.

Thanks &regards
achu

Reply

Radha May 2, 2010 at 9:36 pm

Hi Anshoo,

Typo mistake….for above elseif statement,
elseif uname = ‘invalid username’ or Password = ‘invalid Password’ then
msgbox “Username or Password are invalid”

The method that you have explained in section above seems to be much easier to understand and also in systematic way. That is first checking whether webedit, buttons, etc exists and then checking for there validations. I think i’ll go with above script of yours and execute.
Doing a very good job for a beginner like me… Thanks a lot.

Radha

Reply

ravi October 13, 2010 at 2:36 am

Hi anshoo am a intermediate in QTP programming. i want to know what it represents Exist(15). am aware of Exist.

Thanks in Advance

Reply

Anshoo Arora November 14, 2010 at 5:05 pm

Exist(15) means you’re forcing QTP to wait for an object to exist within a maximum timeout of 15 seconds.

Reply

sushant kumar April 27, 2011 at 1:34 am

Hi Anshoo
I am new in qtp , I just want to know where we can write a code and how to execute. how to implement a test cases

wating for your reply

Thanks
Sushant

Reply

Anshoo Arora May 19, 2011 at 7:33 pm

@Sushant: You can write custom code in Expert View. To implement a test case, you will either have to code out your script or you can Record against your application and Playback to test.

Reply

Anshoo Arora February 16, 2012 at 10:45 am

Jaideep, it depends on personal preference really. I prefer Type1 you’ve listed and use Type2 only when I am using Description Objects. They will both do the same thing.

Reply

Jaideep Patel February 16, 2012 at 10:39 pm

Thanks a lot Anshoo. You really are a great help. Please keep up the good work. :)

Reply

{ 3 trackbacks }

Previous post:

Next post: