Relevant Codes

A Test Development Resource for HP QuickTest Professional.

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

August 12, 2009 · 66 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)

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.

{ 3 trackbacks }

Descriptive Programming (DP) Concepts – 2 {Regular Expressions} | Relevant Codes
August 18, 2009 at 3:55 am
Descriptive Programming (DP) Concepts - 3 {Ordinal Identifiers & Demo} | Relevant Codes
August 18, 2009 at 3:56 am
QTP: Descriptive Programming Concepts - Part 1 in DP Series | Relevant Codes by Anshoo Arora
September 7, 2009 at 7:36 pm

{ 63 comments… read them below or add one }

1 Raj kumar September 21, 2009 at 8:20 am

Please post the DP for Repository in next phase

Reply

2 Anshoo Arora September 21, 2009 at 7:48 pm

Raj,

DP for Repository? Can you please clarify? Thanks!

Reply

3 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

4 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

5 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

6 Anshoo Arora September 29, 2009 at 6:54 pm

Thank you so much for your kind words. :)

Reply

7 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

8 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

9 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

10 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

11 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

12 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

13 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

14 Anshoo Arora October 21, 2009 at 5:41 pm

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

:)

Reply

15 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

16 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

17 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

18 Anshoo Arora October 28, 2009 at 10:06 am

That sounds good!! :)

Reply

19 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

20 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

21 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

22 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

23 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

24 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

25 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

26 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

27 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

28 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

29 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

30 Anshoo Arora November 19, 2009 at 12:12 pm

Most welcome :)

Reply

31 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

32 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

33 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

34 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

35 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

36 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

37 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

38 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

39 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

40 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

41 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

42 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

43 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

44 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

45 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

46 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

47 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

48 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

49 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

50 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

51 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

52 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

53 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

54 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

55 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

56 Anshoo Arora February 19, 2010 at 1:17 am

Thank you, Achu :)

Reply

57 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

58 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

59 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

60 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

61 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

62 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

63 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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: