Introduction
Descriptive programming has become the technique of choice for many QTP test developers. We can talk about its advantages and disadvantages all day, but here, we’ll only discuss the concepts and come up with our own idea of what it does better, and what it doesn’t :). This is going to be a very quick refresher before we move on to its everyday application by completing an end-to-end testcase.
The idea behind descriptive programming is for automation developers to instruct QTP which properties they would like to use to identify an object, instead of having QTP to choose them itself. If done correctly, this can help create robustness in scripts, ultimately requiring less maintenance-time and more development time.
Let’s begin.
But wait, before we really begin, we must understand QTP’s Object Spy. It is an inbuilt tool that enlists all of the test-object and runtime-object properties. These properties are different for different types for objects. For example, an image has a property called ‘file name’ whereas a listbox doesn’t. Instead, a listbox has a special ‘all items’ property whereas the image doesn’t. This discussion will be limited to the usage test-object properties to identify objects. Below are 2 snapshots of the Object Spy:
Now, let’s open www.Google.com and use the object spy to retrieve all properties of the search box:
Notice the image above. The editbox has a HTML TAG property with its corresponding value ‘INPUT’. This means, the editbox takes some input from the user – which is true because we do set some value in it! It also has a ‘MAX LENGTH’ property, with a value of ‘2048′. This means, you can enter a maximum of 2048 characters in it (the best source to see all of the Test-Object properties of objects is the QTP help itself). Below you will see an editBox which can contain a maximum of 9 characters:
Test maxLength:
You can really use all these properties to identify this editbox, but, do we really need to use all of them? No. That is the most important idea behind descriptive programming – we only use what we need. Below is how we write descriptions for objects:
ObjectClassName("property:=value", "property:=value") ' ofcourse we're not limited to only 2 properties. We can write more: ObjectClassName("property:=value", "property:=value", "property:=value")
Above, ObjectClassName (in Web applications) can be Browser, Page, Frame, WebEdit, Image etc. Properties come from the left column the ObjectSpy column whereas values are in the right column. We can include as many properties as we want, but in reality, we only need to add a few to uniquely identify the object. Knowing which properties should suffice to uniquely identify can object will come from experience and practice. Below is a description I created for this editbox (WebEdit):
'ObjectClassName( "property1:=value1", "property2:=value2" ) WebEdit( "name:=q", "html tag:=INPUT" )
I already mentioned the HTML TAG and its value INPUT above. We’ve also added a new property/value here: ‘name:=q’. Is this enough to uniquely identify the object? Yes. But is it enough to make our script work? No, sadly its not.. and that is because, we haven’t yet created descriptions for its parent objects: Browser & Page. Below are the snapshots of the spied browser and page objects:
Browser description:
'ObjectClassName( "property1:=value1" ) Browser( "title:=Google" )
Page description:
Page( "title:=Google" )Now, we will connect all these descriptions and form a hierarchical tree:
Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","html tag:=INPUT")
You might wonder why I have omitted the WebTable below the Page and above the WebEdit object. In practice, we can also skip the Page object to identify the WebEdit. But, why did I skip the WebTable after all!? When you experiment more with DP, you will discover that some objects are embedded in many WebTables, and it will become cumbersome if we were to include all WebTables in the hierarchy to get to the object of interest (thanks to the person who thought that will be a terrible idea!). Example of the previously mentioned scenario:
To complete the statement above, we will add an event. In QTP, events can be described as actions on target objects. For example, a WebEdit has a ‘Set’ event. we use the ‘Set’ method of a WebEdit to set a value:
Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","html tag:=INPUT").Set "DP"
Set is a QTP event to put in a value in the edit box. Different objects have different events. For example: an Image has a ‘Click’ event associated with it.
This, we did without using Object Repository. The same concept applies to all objects regardless of what your environment is. We perform actions on child objects by accessing their object hierarchies. Let’s complete the above example by searching for our keywords (use the spy again on the search button):
Browser("title:=Google").Page("title:=Google").WebEdit("name:=q", "html tag:=INPUT").Set "DP" Browser("title:=Google").Page("title:=Google").WebButton("name:=Google Search").Click
This is how the same code will look like if we had recorded this process:
Browser("Google").Page("Google").WebEdit("q").Set "DP is great" Browser("Google").Page("Google").WebButton("Google Search").Click
These properties are now stored in QTP’s Object Repository (OR). There is another way we can create object descriptions, which is done by setting a reference:
' Creating Browser description ' "title:=Google" Set oGoogBrowser = Description.Create oGoogBrowser( "title" ).value = "Google" ' Creating Page description ' "title:=Google" Set oGoogPage = Description.Create oGoogPage( "title" ).Value = "Google" '* Creating WebEdit description ' "html tag:=INPUt", "name:=q" Set oGoogWebEdit = Description.Create oGoogWebEdit( "html tag" ).Value = "INPUT" oGoogWebEdit( "name" ).Value = "q"
Once we do the above, we can use this descriptions in our script:
Browser(oGoogBrowser).Page(oGoogPage).WebEdit(oGoogWebEdit).Set "DP is great"
The only time I use this technique is to retrive object collections through ChildObjects (we will discuss this in the coming tutorials).
Let’s do another example. Again, we will use Google, but instead of setting a value, we will click an object. You can choose any Link on the page; I chose the link ‘Images’:
'ClassName("property:=value").ClassName("propert1:=value").ClassName("property:=value").Event Browser("title:=Google").Page("title:=Google").Link("innertext:=Images", "html tag:=A").Click
This time, instead of ‘Set’ we used ‘Click’. Following is a list of events we perform on Web objects:
| Object | Event |
|---|---|
| Image | Click |
| WebButton | Click |
| WebCheckBox | Set |
| WebEdit | Set |
| WebElement | Click |
| WebList | Select |
| WebRadioGroup | Select |
Descriptive Programming Series
- Descriptive Programming (DP) Concepts – 1
- Descriptive Programming (DP) Concepts – 2 {Regular Expressions}
- Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}
- Descriptive Programming (DP) – 4 {Creating a Test Script)
References
- QuickTest Professional Help
If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.
{ 71 comments… read them below or add one }
Your introduction to Descriptive Programming is awesome! It is concise, well-explained and I found it really helpful.
Thanks
Thanks! :)
Hello Anshoo,
You seems to be another expert in the field of QTP and I am deeply impressed by your posts which truly represents your vast experience along with your expertise. I have a question for your that may sound silly to you( as I am a QTP beginner). Still m taking courage to ask: I read in the QTP help file that :
###########################################################
Note for users of previous QuickTest versions: When you open a test that
was created using a version of QuickTest earlier than version 9.1, you are
asked whether you want to convert it or view it in read-only format.
Whether you choose to open it in read-only format or convert it, the object
repositories are associated to the test as follows:
➤ If the test previously used per-action repositories, the objects in each
per-action repository are transferred to the local object repository of each
action in the test.
➤ If the test previously used a shared object repository, the same shared
object repository is associated with each of the actions in the test, and
the local object repository is empty.
#############################################################
I have a doubt in the second point. What if my test created in a previous version (say QTP 9.0 ) contains both Local and Shared OR. So as per the second point will be Local OR will get deleted as it is saying the local OR is empty??
Regards,
Shivani
Hi Shivani,
If your test contains both Shared and Local Object Repositories, then:
1. Your Local Repositories will be transferred to the local repository of each action in the test, as mentioned in the first bullet point.
2. Your Shared Repositories will be associated with the same test, but since you also have Local Repositories, in your case, your Local Repositories won’t be empty. They will contain information from #1 above.
I hope this will clarify your doubt. :)
-Anshoo
Hi Anshoo,
Doubt cleared :)
One more doubt in your article..
You have mentioned: We can skip the Page object..So which is the best coding method
OR
Is there any particular case where we can say First method is the best one and also the case where we can say second method is the best one?
Excellent question, Shivani! You’re the first one to catch that.
.. and to be honest with you, its one that’s quite hard to answer. Performance wise, there is a negligible difference between the 2 techniques. Usage wise, they both work quite well and are equally readable. That is, the reader can always make out what the script is doing between both methods.
Therefore, in the end, it bottles down to personal preference. I use the 2nd one in your post 90% of the time, and I have not yet come across a situation when it failed to work. But, please note that when you are using ChildObjects to retrieve an object collection, you must specify the complete hierarchy:
Other than that, I guess its just a personal preference. If you browse other QTP sites/forums, you will see the first approach used the most. I know this answer isn’t satisfying, but I hope you will be able to choose one that you would like to use extensively. :)
Thanx for the explanation..Your answer is really satisfying for me.. Thank you so much Anshoo..
Hi Anshoo,
Your knowledge and the way , you explained the things, just great. really really fantastic…
There are so many sites and blogs , explaining all these kind of QTP stuffs, but your’s I found different.
Thank you, Vikas. I’m very glad that you found it useful. Likewise, if you saw some areas needing improvement, please do let me know. :)
Thanks- Anshoo
Hi Anshoo ….
I read ur articles and codes which u gave , they are really very good …. it seems that ur expert in QTP….
I’m learning QTP these days … i hope u can provide help on that.
Thanks
Thanks! :)
Please feel free to ask any questions that you may have. I will try my best to help you.
Greetings !
I appreciate the work being done by you for the QuickTest newbie’s.Anshoo,as a member of AdvancedQTP forum, your solutions for the queries are very simple and easily understandable even for the newcomers. Great Job!
Please make me clear with the Recovery Scenario.
As every tester wants the script to be continued after particular recovery event has been handled then why don’t they use “If then else” instead of a calling a .vbs or instead of using a recovery manager.
When ,How and Where should i use recovery scenario.
Have a nice time
Kiran
When using Conditional Statements, you know that might happen here, and create conditions to tackle expected behavior of the application. For example, you may create the following Conditional Statement:
If Browser("").Page("").WebEdit("").Exist(0) Then Reporter.ReportEvent micPass, "WebEdit", "The WebEdit was found!" Else Reporter.ReportEvent micFail, "WebEdit", "The WebEdit was not found!" End IfAbove, you know that there can be only 2 conditions for the WebEdit – that it exists, or it does not.
The same cannot be said when using Recovery Scenario. The reason why they’re called Recovery Scenarios is that, they help us Recover from something we do not expect. For example, you’re running a script and IE crashes. What do you do now? If you have a Click event right after IE shuts, QTP will throw a run-time error and your script will stop. This is where you may want to use a Recovery Scenario because you’re trying to handle an error that you would not normally expect.
The above example may be an extreme case, but I hope it clarifies the main difference between the two. One is where you expect what might happen, whereas, the other helps you overcome an issue that you would not normally expect to occur during run-time.
I hope this helps. If you’re still unclear, or have another question after reading my reply above, please feel free to ask! :)
Anshoo
The reason why i said so is that we never had a situation other than handling the pop-ups.Let me assume that IE crashes while performing a DD testing.Suppose IE crashes at TestIteration no 50 and still 40 to finish.Will the script execute from 51 or 1? How to overcome such issues?
And also as we are unsure where exactly this might occur,we need to instruct the QuickTest to check on every line in the script for recovery which degrades the Tool performance.Doesn’t it?
I am elaborating this topic so that i can get a clear idea about recovery scenario. Thanks for the reply.
Kiran
Hi Kiran,
I appreciate your interest in learning more, and making your concepts clear.
In such a case, you have the following 6 possible steps to choose from:
In other words, you can choose any of the 6 possible choices above. If you would like to exit, then you can do that as well.
Technically, we don’t instruct QTP how to use the Recovery Scenario, we just tell it what should trigger it. QTP finds if an application state matches with what we have in our scenario and activates the trigger.
As for performance, it may impact it, but by only a little, I hope. They’re triggered only when QuickTest encounters a particular application behavior. You may be correct in saying that QTP may check after each executed line whether to trigger the Recover Scenario or not. However, I’m not too sure about this. Possibly someone at HP can answer this for us.
That’s great, Kiran. I feel I should learn more about Recovery Scenarios myself. Clearly, my knowledge on this subject is not vast enough to answer your questions accurately. This is going to be an action item, then!
Hi Anshoo,
In search of Recovery Scenario i have gone through many forums and blogs but could only find the all-known pop up error handling.And also i found all the forums and blogs have almost same topics and examples about the QTP.
If you can provide video tutorials,with real time issues, that will be a great help for the visitors.Thanks for the reply!
I haven’t tried it yet but will let you know the outcome once done.
Have a nice time
Kiran
Sure, Kiran. I will try my best to help you.
Hi Kiran,
An article on Recovery Scenarios has been published here a few days ago. I thought you might be interested.
I was not able to record a video, but I have included several snapshots to try to cover up the visual component. Hope you like it. :)
Hello Anshoo
M here to trouble you again with a very annoying query of mine.
See this website :–> http://in.buzz.yahoo.com/ In this website, you will see a Yahoo logo image at the top. I am not able to click this logo using descriptive Programming though I am able to do so with the help of Object Repository. I tried various combinations but nothing worked. I am using QTP 9.2 with IE 7.
This is the code I tried:
Browser(“micclass:=Browser”).Page(“micclass:=Page”).Image(“html tag:=IMG”,”image type:=Image Link”,”alt:=Yahoo! Buzz India (TM)”).Click
It didnt worked. When I record on this image, the learned/mandatory properties are these three only . I am really confused what to do…
HI Pragya,
You can try any of the solutions below:
Browser("title:=.*Buzzing.*").Image("file name:=buzz_logo_.*").HighlightBrowser("title:=.*Buzzing.*").Image("file name:=buzz_logo_tm_in_033109.gif").HighlightBrowser("title:=.*Buzzing.*").Image("alt:=Yahoo! Buzz India \(TM\)").HighlightBrowser("title:=.*Buzzing.*").Image("name:=Image", "index:=0").HighlightI hope this helps :)
Hi Anshoo,
I am the beginer of QTP I want to learn Regular Expression conpet and Parameterization concept in QTP.
What is the use of both things can u explain the things with good real time example.I need those things please help me on this.
Hi Satish,
Please see my other comment here about Regular Expressions. I am currently working on an article on Parameterization, and hopefully I will try to have it released soon.
In the meantime, to give you a brief overview, Parameterization is a technique in which you replace an actual value or an entity with a variable. That variable in turn, retrieves values from a data-pool and uses those values to drive the automation. For example, consider the following statement:
Browser("Google").Page("Google").WebEdit("Search").Set "Descriptive Programming"We can replace the “Descriptive Programming” bit with a Parameter:
Browser("Google").Page("Google").WebEdit("Search").Set sTextNow, in our table, we can have the following structure:
Therefore, the first time our code executed, sText will take “Descriptive Progamming” as input and write that value to our Search Box. In the 2nd iteration, Regular Expressions will be written.
I hope this helps..
Hello Anshoo,
great site and very accurately written topics and answers on questions!
Can you please help me on something… I’m trying to work out how to refer to a webelement in a webtable by DP and a parameter as innerhtml. Maybe you have already described how to do this, but I couldn’t find it here (if so post a link, please).
I want to use something as [...] .WebElement(“innertext:=ObjectText”).Exist
while ObjectText is used as a parameter which I have already defined. This should be very simple to do if only I knew how to… I prefer to reference the cell text than to use an index because the text can be anywhere in the table.
Thanks a lot, Stefan
Sorry, in the example Is used I mean innertext of course, not innerhtml. In my case, innerhtml and innertext are the same anyway. This is meant as a very general question, the same problem could be a reference to a website by parameter or something else.
OK, found out about it…
[...] .WebElement(”innertext:=” & ObjectText).Exist
Not very difficult I must admit, but I first experienced that it didn’t work this way for some reason.
Hi Stefan,
I’m glad you figured it out. Whenever a value comes from a variable in a description, you will have to use the “ampersand &” character.
:)
Hi Anshoo,
again I’m having a question. I want to set global variables I’m using for several QTP-actions, such as
Set Google = Browser(“name:=Google”).Window(“text:=Google”)
Now I can only use this within the same action. How can I do this, will I need to define a public class I’m calling in each action?
Thanks, Stefan
Hi Stefan,
You can use a function library and declare the variable ‘Google’ as public within the library:
This will enable all actions to have complete access to your variable/reference.
Hello All,
I am having issue with QTP
I have a Web table which has webelements in few cells, My application has Few cells which are Webelements and when double clicked will be Web Edits,
When i Spy the Object on each cell is shown as WebElement. however when I try to get the count the value is 0. I was wondring if we can work with Webelements in descriptive programming
ObjectCount2 = Browser(“Browser1″).Page(“Page1:”).Frame(“main_iframe”).WebTable(“name:=CCV-100″).ChildItemCount(3,iColIndex, “WebElement”)
Print ObjectCount2
Please help me
Hi Naresh,
Is the cell itself a WebElement, which is to be clicked? Or, does the cell contain an element that you click?
If the cell itself is an element that you need to click, then you can use DOM methods instead:
Browser("Browser1").Page("Page1:").Frame("main_iframe").WebTable("name:=CCV-100")_ .Object.Rows(2).Cells(iColIndex-1).ClickHello Ashoo,
Thnaks for the Quick Response, This has resolved my 30% of the issue,
The Issue is Few Cells in Table are Webelements, When Double clicked, will become WebEdits, where I set the values or Edit the Values depending on test requirements. now th issue is when i use the Above DOM Concept will resolve the problem of clicking the Row and column in table, however this Dom doesnot support the Set or Type the values to those cells.
I am New to the DOM concepts, if you can guide me to study material, i would really Appreciate the time and Effort.
Thanks a lot
Regards
Naresh
After you click the cell, the exposed WebEdit should technically support the .Set statement. If that does not work for any reason, you can try this as well:
Browser("").Page("").WebEdit("").Object.Value = "Test"Also, you can check W3Schools for a HTML DOM tutorial: http://w3schools.com/htmldom/default.asp
First of all, I would like to thank and appreciate for coming up with such a nice Knowledge Resource on QTP. Great piece of work, indeed…!! I consider myself as a beginner in QTP and I am trying to learn the concept of Descriptive Programing. I found your website, read the articles and could not stop writing to you.
The way you present things and describe them is really very neat and clear, and impressive too. I found your site very different from others as I went through many QTP sites and blogs and know what they have. Sometimes, your comments and replies are much valuable than your articles….. :) That’s really nice. Now, I know I am in right place. So, I will start firing questions to you. I am sure you would address them with the same spirit, enthusiasm and patience.
Last but not the least, thanks for guiding beginner like me. All the best…….!!
Regards
Debajit
Thank you Debajit. Thank you for your kind words. I’m deeply honored. :)
Please feel free to use the comments section of the relevant posts for your queries. I will try to answer them as quickly as possible.
Regards,
Anshoo
Hi Anshoo,
I ve small query. ” I ve generated one test script and when i copy the intire folder of this QTP script( must be along with repositories) for same test in different machine.it is throwing error.what can be the reason? pls specify
Thanks
Renu
Hi Renu,
What is the error message? Have you copied the contents to the same location in Machine2 from Machine1?
Hi Anshoo,
I try doing a wildcard by indicating “CN=.*”, but that didn’t work, how can I do a wildcard on this selection statement CN is equal to the machine name so there will be different machine that wil added to so the name will change. Thanks
SwfWindow("some window").SwfWindow("DCS").SwfWindow("Network Conduits").SwfWindow("Select Certificate").SwfListView("certificateListView").Select "CN=mc4-srv3xxx"Puneet,
Try this:
Public Function RegexSelect(ByVal Object, ByVal sItem) Dim sAllItems, oRegExp, oMatches sAllItems = Object.GetROProperty("all items") Set oRegExp = New RegExp oRegExp.IgnoreCase = True oRegExp.Pattern = ";" & sItem & ";" Set oMatches = oRegExp.Execute(sAllItems) If Not oMatches.Count > 0 Then oRegExp.Pattern = ";" & sItem Set oMatches = oRegExp.Execute(sAllItems) End If If Not oMatches.Count > 0 Then oRegExp.Pattern = sItem & ";" Set oMatches = oRegExp.Execute(sAllItems) End If If oMatches.Count > 0 Then sMatch = oMatches(0) sMatch = Replace(Mid(sMatch, InStrRev(sMatch, ";", Len(sMatch) - 1), Len(sMatch)), ";", "") Object.Select "" & sMatch End If End Function RegisterUserFunc "SwfListView", "RegexSelect", "RegexSelect"Usage:
Hi Anshoo,
I am facing issue with Web List object in my script what happening QTP is performing this action sometime but sometimes it tires to skip this action? can you help me here please
Browser(“S”).Page(“S”).WebList(WebListID).FireEvent “onmouseover”
Browser(“S”).Page(“S”).WebList(WebListID).Object.Click
Browser(“S”).Page(“S”).WebList(WebListID).Click
Browser(“S”).Page(“S”).WebList(WebListID).FireEvent “OnClick”
Hard to say what might be happening here. Are you running your test in Fast mode? Does the issue persist in Normal mode as well?
Hi Anshoo,
Can you please help me to understand below script with an example? It is actually checking whether elements in a Weblist are in Alphabetical Order or not.
arrCtry=Split(Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items"),";") Set objArray=DotNetFactory.CreateInstance("System.Collections.ArrayList","") For i=0 to Ubound(arrCtry) If arrCtry(i)"--Choose One--" Then objArray.Add(arrCtry(i)) End If Next objArray.Sort() objArray.Insert 0,"--Choose One--" For j=0 to Ubound(arrCtry) strOuput=strOuput+objArray(j) strOuput=strOuput+";" Next If strOuput=Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items")+";" Then Msgbox "The Weblist's values are sorted in alphabetical order" Else Msgbox "The Weblist's values are not sorted in alphabetical order" End IfThanks,
Radhika
Hi Radhika,
Please see the comments below:
'There are 2 parts to the below statement: '1: Retrieve the 'all items' property of the list: it contains all items that are visible in the ListBox '2: Split above statement with the delimiter ; arrCtry=Split(Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items"),";") 'System.Collections.ArrayList Class: http://technet.microsoft.com/en-us/magazine/2007.01.heyscriptingguy.aspx Set objArray=DotNetFactory.CreateInstance("System.Collections.ArrayList","") 'Looping the array created in 'arrCtry' 'If there is a match found, add the object in the ArrayList Class(objArray) For i=0 to Ubound(arrCtry) 'If a match is found: If arrCtry(i) = "--Choose One--" Then 'Adding the object here: objArray.Add(arrCtry(i)) End If Next 'Sort the ArrayList in ascending order objArray.Sort() 'Insert a new value at the very first position objArray.Insert 0,"--Choose One--" 'Execute another loop and create a single string of values: strOutput 'strOutput = "--Choose One--;Match1;Match2" etc. For j=0 to Ubound(arrCtry) strOuput=strOuput+objArray(j) strOuput=strOuput+";" Next 'If the 'all items' property of the WebList matches the Sort operation above, then its a sorted list If strOuput=Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items")+";" Then Msgbox "The Weblist's values are sorted in alphabetical order" Else Msgbox "The Weblist's values are not sorted in alphabetical order" End IfHey Anshoo,
Thanks for the explanation. It helped to understand.
But am still wrong output when run the above script. It is giving “not in alphabetical order”
Below is the code.
Set objarray=Dotnetfactory.CreateInstance(“System.Collections.ArrayList”,”")
For i=0 to ubound(arr)
If arr(i)”Acapulco” Then
objarray.add(arr(i))
End If
Next
objarray.sort()
objarray.insert 0, “Acapulco”
For j=0 to ubound(arr)
stroutput=stroutput+objarray(j)
stroutput=stroutput+”;”
Next
Other things are same…
Kindly help
Radhika
Radhika,
try this:
Dim arrArray, oArrayList, sElement 'Create an array with elements in Ascending Order arrArray = Split(Browser("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("all items"), ";") Set oArrayList = CreateObject("System.Collections.ArrayList") For Each sElement in arrArray If IsNumeric(sElement) Then oArrayList.Add CInt(sElement) Else oArrayList.Add sElement End If Next 'Sort Ascending oArrayList.Sort 'Verify all elements in the Ascending array with the sorted oArrayList For x = LBound(arrArray) to UBound(arrArray) 'If the array element does not match the sorted element, then the original 'array is not in ascending order If Not arrArray(x) = oArrayList(x) Then MsgBox "Not Ascending" Exit For End If NextIt will only throw a MessageBox if the list is not in ascending order.
Hi Anshoo,
Can you Please explain how to write script to check the default value for drop down, radio button, etc. Do we need to insert checkpoint or is there any other way.
For eg: Drop down “Passengers” is having default value “1″
Drop down “Departing from” is having default value “Acapulco”
Kindly help.
Thanks,
Radhika
Hey Anshoo,
For the above query, I have tried the following method. Let me know if i am going wrong.
‘Inserted Standard Checkpoint first
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Check CheckPoint("fromPort") 'Then tried to retrieve run time value fromport=browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty("value") If fromport="Acapulco" Then reporter.ReportEvent micPass, "Default Drop down", "Departing from default drop down value is valid" else reporter.ReportEvent micFail, "Default Drop down", "Departing from default drop down value is invalid" End IfRegards,
Radhika
Radhika,
You have the correct idea, and after sharpening a few corners, you will be able to create great scripts!! Please see my feedback to your code above:
Dim fromPort 'As the page loads, execute these statements: If Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Check(CheckPoint("fromPort")) Then fromPort = Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty("value") End If 'Place this code where the CheckPoint is to be performed If fromPort <> "" Then If fromPort = "Acapulco" Then Reporter.ReportEvent micPass, "Default Drop down", "Departing from default drop down value is valid" Else Reporter.ReportEvent micFail, "Default Drop down", "Departing from default drop down value is invalid" End If Else Reporter.ReportEvent "fromPort", "Value was not retrieved. Critical Error!" End IfYou can simply retrieve the “value” property as the new Page loads. This will always give you the default property. :)
Hey Anshoo,
Thanks a lot….I tried your above script…….Came to know one new method…..Your words are really encouraging….:)
Regards,
Radhiks
Hi Anshoo,
I had recorded a script using default Flight Reservation sample second’s page.
Parameterised FromMonth and FromDay drop down. Now when running the script it is not going for 2nd iteration since click on Continue button at the end lands on next page. so not coming back to previous page.
How should i run all the iteration.
Note: Have started recording directly from second page so there is not login.
Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebRadioGroup("tripType").Select "oneway" Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("passCount").Select "2" Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort").Select "Frankfurt" Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromMonth").Select DataTable("From_Month", dtGlobalSheet) Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromDay").Select DataTable("From_Day", dtGlobalSheet) Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("toPort").Select "New York" tomonth=Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("toMonth").GetROProperty("value") today=Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("toDay").GetROProperty("value") Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebRadioGroup("servClass").Select "Business" Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("airline").Select "Blue Skies Airlines" Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").Image("findFlights").Click 46,11Kindly help.
Hey Anshoo,
That was really a very silly question which i asked you. Sorry to bother. I should have recorded one more step at the end to return to same screen again to continue all my iterations.
Radhika
You must include the code to navigate back to the Parametrized page. Please read this article: it shows how a parametrized scenario is a cyclic process beginning from Page 1 and returning back to Page 1 for the next scenario to execute.
Hi Anshoo,
Great explanation. your examples are very easy to understand. I am beginner with QTP and refer your blog for reference.
I need your help for the following.
Var1=Browser(” “).Page(” “).WebList(” “).Select (DataTable(“Desc”, dtGlobalSheet))
msgbox Var1
I have parameterised value and trying to retrieve its value using a variable and display same using message box. But cannot.
How do i do this. Cos for further validation i need the value from table.
Regards,
Vrinda
This statement:
Var1=Browser("").Page("").WebList("").Select (DataTable("Desc", dtGlobalSheet))is selecting a value from the Test Object. It will not retrieve any result. To retrieve the selected value, you must use
GetROProperty:Browser("").Page("").WebList("").Select (DataTable("Desc", dtGlobalSheet)) Var1 = Browser("").Page("").WebList("").GetROProperty("value") MsgBox Var1Thanks Anshoo for quick reply.
Actually i also tried with the following method. Let me know if it is correct?
Browser(“”).Page(“”).WebList(“”).Select DataTable(“Desc”, dtGlobalSheet)
Var1 = Datatable.Value(“Desc”, dtGlobalSheet)
MsgBox Var1
Regards,
Vrinda
Technically, if no error occurs, it will always work. However, if the value from the DataTable is invalid, it will certainly result in a run error. When that happens, Var1 will denote the value that *was selected*, when in reality, it was not..
Hi, Anshoo,
I want to get a solution from you for a questions.
Using your example:
and then
Now, there is an assumption that we don’t know the object class of “oGoogWebEdit” is “WebEdit”, and then how can I identify it in QTP by DP?
I have tried that
It cannot work.
And also I try to use the following:
(Because I originally realize that all the objects can be identified as WebElement.)
even
(Because I suppose there is a “Object” class…)
Both of them cannot work.
Is there any solution for identify the object by DP when I don’t know the exact object class in QTP?
Thank you in advance.
Regards,
Dennis
Hi Dennis,
If you open the Object Spy and for a WebElement object, if you notice the supported Operations, you will find that it does not support the
Setevent. Also, when building object hierarchies, you must always specify the Test Object. Either that, or replace the Test Object with an object collection of the same class.Hi, Anshoo,
Thanks. I think your concept is useful, and then I’ve found the approach.
I think the following code can help me to ignore to know the Test Object.
But this approach has a prerequisites. That is
must be able to identify only one specified object.
Anyway, I think this is a well workaround, and I didn’t see any risk here for now.
Thank you again, Anshoo.
Regards,
Dennis
That’s true :)
Its the same as using the collection object in a loop, which you see more often:
For ix = 0 to oParent.Count - 1 oChildObjects(ix).Highlight NextHi anshoo!!
I have installed QTP 9.2 on windows 7. But, QTP is not able to recognise IE as a web browser. It is showing it as a win object. The problem is same with even QTP 10.0 (trial version). Do u have any solution for this?? I even tried by registering the browser in QTP.
The patch QTP_00644 must be installed on Windows 7 for QTP to work. Also, I’m not sure if QTP 9.2 is supported – you will have to install QTP 10.0.
Hello Anshoo!!
Thanks for clearing my previous issue.
Currently, I am facing a problem with my QTP script. I am using systemutil.Run method to open ie and run my web application. But, the problem is when I need to do some volume test, I am using data table. Now, when the second row of the data table is executing, due to the systemutil.Run, another browser is opening and am getting a run error. I need a solution to recover my script from this general run error.
Thanks.
You will have to handle SystemUtil.Run with a conditional statement:
If Environment.Value("ActionIteration") = 1 Then SystemUtil.Run "", "" End IfBut the above is going to be a little tricky if your test does not always start with the first iteration. For that, you may be required to store the action iteration in a variable and use that variable in your test:
'When the test starts: in global file iFirstIteration = Environment.Value("ActionIteration")and within your Action:
If Environment.Value("ActionIteration") = iFirstIteration Then SystemUtil.Run "", "" End IfHi Anshoo,
Great explanation. your examples are very easy to understand.I am working in QTP for the first time.
I read your articles on Descriptive Programming.(DP Concepts 1).Really nice work.
I ‘ll describe you the scenario.Kindly help me in doing the same.
1) There is a weblist from which i have to Select No of claims eg.One claim/Two claim/Three Claim
2) Depending on the Selection,the WebEdit boxes and Weblists get populated i.e.If i select One claim,One webedit and one weblist gets populated(two more webedits/weblists)
The issue is that as all the objects(WebEdits and Weblists) have diffrent names,I have to code for all of them seperately.Is there any other approach(DP/anyother) that i can follow so that I need to write less code.
Please help.I shall be very thankful
You can create a single loop to deal with all objects at once, depending upon how they are created. I think this article may be a little helpful to get started..
I have tried using regular expressions for the same.But then only the first Weblist gets identified..(even if i select 2 claims)The remaining ones does not get identified.Please guide
Rajni, you may have to use Index to identify the second one. Plus, you can read the article I mentioned in my previous post.. It explains how DP can be used to create descriptions at run time, which is what your scenario looks like.
Thank you Anshoo.I shall try out the way you have mentioned.
Hi Anshoo,
Thanks so much..The article was really easy and simple to understand.You have great explanatory skills..
Thanks again
{ 6 trackbacks }