LoadRunner VIDEO tutorial - Parameters part1 ('Select next row' = 'Sequential')

I've prepared new LoadRunner video tutorial on working with LoadRunner parameters.
The present LoadRunner video tutorial covers the following:
  • How to create new LoadRunner parameter
  • How to use 'Simulate Parameter' feature
  • Settings on Parameter List dlg
    Option 'Select next row' = 'Sequential'
    Option 'Update value on' = 'Each iteration'
    Option 'Update value on' = 'Each occurrence'
    Option 'Update value on' = 'Once'
  • How to view an output value of parameter

How to get text of Status Bar from QTP?

When you work in QTP with Web applications, it is sometimes necessary to get a text of browser's status bar.
Let's see for example the following browser:

How to get text of Status Bar from QuickTest Professional?
There are two ways:
  1. Object.StatusText property of Browser object
  2. GetROProperty("text") method of WinStatusBar object

  1. Getting text of Status Bar using Object.StatusText property of Browser object

    To access text of Status Bar, we use Browser's Object object and its StatusText property.
    Browser("bname").Object is a reference to the Internet Explorer's DOM object. To be more precise, it's a reference to the Internet Explorer's IWebBrowser2 interface.

    Using Browser("bname").Object, you can access different methods and properties of IE, for example:

    #
    Statement
    Meaning
    1
    Browser("bname").Object.GoBackNavigates backward one item in the history list
    2
    Browser("bname").Object.LocationURLGets the URL of the page that is currently displayed
    3
    Browser("bname").Object.StatusTextSets or gets the text in the status bar for the object
    4
    Browser("bname").Object.ToolBarSets or gets whether toolbars for the object are visible

    So, our code is simpe enough:
    sText = Browser("QTP - How to get Status").Object.StatusText
    MsgBox sText
    And its result is:
    Note: Since we use Internet Explorer's IWebBrowser2 interface, we can use this solution win IE only. It doesn't work with FireFox. The next solution will be compatibe with both IE and FF.


  2. Getting text of Status Bar using GetROProperty("text") method of WinStatusBar object

    Status bar is a part of browser's window. There is a special class to handle it from QTP - WinStatusBar. We can get text of WinStatusBar using GetROProperty("text") method.

    So, I add Status Bar to QTP's Object Repository (OR):
    QTP Object Repository
    The final script is:
    sText = Browser("QTP - How to get Status").WinStatusBar("msctls_statusbar32").GetROProperty("text")
    MsgBox sText
    And its result is:
    Result of QTP script
    Note: This solution works correctly both for IE and FF, but it requires additional operations with Object Repository.

Summary:
Two approaches were shown.
Both do the same - they get text of Status Bar from QTP.

Which approach is prefferable?
Actually, it's up to you.
As for me, my choice is a compatibility. So, I prefer using of WinStatusBar object.


Related articles:


--
Dmitry

QTP - quotes in VBScript

Today I found an interesting question on Ankur Jain's blog.
The question was simple - how to display quotation marks (") in QTP?

There two ways to do that:
  1. Double the quotes (""):
    MsgBox "#1: ""QTP - QuickTest Professional"""
    Use 2 double quotation marks to include a quote character in the string.
    So, the result is:

  2. Use ANSI character code - Chr(34):
    MsgBox "#2: " & Chr(34) & "QTP - QuickTest Professional" & Chr(34)
    Since, the ANSI code if quotation mark = 34, we can use Chr function.
    The result is:


Related articles:


--
Dmitry Motevich

[My money] - April 2008 - $58.81

This is a report about money which was earned during the April 2008.
As you can see, my readers helped me to earn $58.81:
(click to enlarge the image)

Google AdSense brings this money... Every time readers click Ad links, the counter increases.
It's simple enough, isn't it? :)

Like last time, I'm planning to contribute this money to automated testing community.
As you remember, the winner then was Charlie Weiblen.


And now I'm going to start a new initiative.
I announce A competition for the best articles on QTP (QuickTest Professional).


What is the prize for a winner?
I'll give all money, earned during April 2008 - $58.81.

What to do?
You have to write an article on any aspect of working with QTP. It can be an interesting solution you investigated, or it can be an understandable description of any QTP feature, or any QTP tool trick, or maybe video on QTP, etc.

How to send prepared articles?
There are different variants. You can place them in your blog or site. Do not forget to mention this competition. And notify me by sending email.
If you don't have a blog or site - don't worry! You can email your article to me and I will publish it in my blog (if you don't mind). So, you will be a part of the team!

What are the criteria for evaluation?
Hm... It's difficult to answer. How the quality of music, films, or paintings could be evaluated?
I think, it's impossible. So, I will evaluate according to my subjective opinion...

Why do I do that?
I just want to do something useful. And I want to help to all my colleagues, who work in a field of automated testing.
I wish that we were one team!

How to contact me?
Dmitry Motevich's email


Thank you in advance, my readers!

--
Dmitry Motevich

QTP Descriptive Programming - How to close all Browsers?

This is a very practical task - How to close all browsers from QTP?
You may need to close browsers before or during the QTP script execution.

You can be surprised, but QTP script, that closes all browsers, will contain 3 lines only:

Well, how does this code work?

To answer, I have to tell about QuickTest Professional Descriptive Programming.
Descriptive Programming (DP) is a working with object, which are not described in QTP Object Repository (OR).
All objects properties are calculated dynamically during the QTP test execution.

Please, check this code:
While Browser("CreationTime:=0").Exist
    Browser("CreationTime:=0").Close
Wend
"CreationTime" is a QTP browser property, which indicates the order in which browsers were opened.

QTP Tip1: The first browser that opens receives the value "CreationTime" = 0, the second browser receives "CreationTime" = 1, and so on...

QTP Tip2: To specify value of property in Descriptive Programming, please use ":=" operator.
For example, "Title:=My application".

Since we cannot know in advance - what browser will be selected and closed, we use its "age", i.e. "CreationTime" property. We decide, which browser should be closed, during the QTP script execution only.


Let's return to above QTP script...
  • Browser("CreationTime:=0").Exist - it checks whether the first opened browser exists or not
  • If the browser exists, we close it - Browser("CreationTime:=0").Close - and repeat checking

Let's continue сomplicating our task:
How to close browsers by mask?

For example, we have to close all browsers navigated to any Google's sites (URL contains 'google.com').

In this case, QTP script will look like:
(Click the image to enlarge it)

Using this QTP code, you can close dynamically browsers by mask.

Please, note several useful QTP tips.

QTP Tip3
: To get browser's URL, use: GetROProperty("URL") function.
For example, this line returns URL of the first opened browser:
Browser("CreationTime:=" & CreationTime).GetROProperty("URL")

QTP Tip2: Analogously, to get browser's Title, use: GetROProperty("Title") function.
Browser("CreationTime:=" & CreationTime).GetROProperty("Title")


Summary:
I've shown and explained:
  • Simple concepts of QTP Descriptive Programming
  • How to close all browsers from QTP test
  • How to close browsers by mask from QTP test

Related articles:


I hope, these simple scripts will be usefull for you. Please, let me know.
Do you have suggestions/materials/questions on QTP? Please, post your comments on my blog.

--
Dmitry Motevich

QTP - getting current browser URL

I'm going to show and explain how to get current URL which is opened in a browser.
For example, how to get URL "http://motevich.blogspot.com" from the following browser:

There are two solutions:
  1. Using GetROProperty("URL") method (run-time object property)
  2. Using "URL" property of "Object" (IE DOM Object)
Let's consider both variants.

  1. GetRoProperty("URL") method (run-time object property)

    GetRoProperty
    function reads properties of a run-time object in an application.
    If you open QTP Help on GetRoProperty function, you 'll see that this function can work with all objects:
    So, for example:
    • to check whether a link is visible or not, use:
      Browser("bname").Page("pname").Link("lname").GetROProperty("visible")
    • to get a page's title, use:
      Browser("bname").Page("pname").GetROProperty("title")
    • to check whether a window is maximized, use:
      Window("wname").GetROProperty("maximized")
    • to get width of WebButton, use:
      Browser("bname").Page("pname").WebButton("btname").GetROProperty("width")
    Others properties are described in QTP Help.

    In our case, to get URL of the current WebPage, we will use:
    Browser("bname").Page("pname").GetRoProperty("URL")
    This is a sample QTP script:
    (Click the image to enlarge it)


  2. "URL" property of "Object" (IE DOM Object)

    The sample syntax is:

    Browser("bname").Page("pname").Object.URL

    What is "Object" in the above statement?

    Actually, this is Internet Explorer Document Object Model (DOM) Object.
    You can read more about DOM here and here.
    Also, I recommend to read this interested article on working with IE DOM from Visual Basic.

    Tip:
    You can use DOM Object when running QTP test on Internet Explorer only!

    To make the long story short, I can say that using Object property you can get almost all elements and properties from Web page.

    Thus, I use URL property of Internet Explorer's DOM Object.
    All properties, collections, and methods of DOM Object are described in this MSDN article.

    Tip:
    The number of properties, accessed via DOM Object, is more bigger, than properties accessed via GetROProperty method.

    So, the result of above code is:
    (Click the image to enlarge it)
Summary:
Two ways were discussed:
  1. GetROProperty("URL") (run-time object property)
  2. "URL" property of "Object" (IE DOM Object)
GetROProperty method supports both IE & FireFox, but IE DOM Object provides more accessible properties and methods.
Both can get URL of the current Web page.


Related articles:


Have you got interested materials or your own thoughts on QTP (QuickTest Professional)?
Let's share them and help each other to improve our skills and knowledge!
You can send them to my email: Dmitry Motevich's email

Thank you in advance, dear readers.

--
Dmitry Motevich

Generating unique file name using LoadRunner parameter

I'm sure that my readers are the best readers in the world!
They are careful and they are great professionals. I constantly learn from them. Indeed!

I want to thank Tim for his comment on getting unique file name in LoadRunner.

Sure, there is very simple way to generate unique file name in LoadRunner using LoadRunner parameters.

How to do that?

We have to create three different types LoadRunner parameters:
  • Vuser ID
  • Iteration Number
  • Date/Time
  1. Open "Parameter List" dialog from "Vuser/Parameter list...":
  2. Add new LoadRunner parameter of "Vuser ID" type:
  3. Then add second LoadRunner parameter of "Iteration" type:
  4. And add third LoadRunner parameter of "Date/Time" type:
    (Click the image to enlarge it)

    Please, note that I added new Date/Time format - "%Y%m%d_%H%M%S.000".
    I described the meanings of %Y, %m, etc in this post. Point and three zeros (".000") means using of milliseconds.
    So, this Date/Time format produce a string like: 20080616_231514.953

  5. That's all. Now I add the following line of code:
    lr_output_message(lr_eval_string("{VuserID}_{Iteration}_{DateTime}"));
    The result of this line is:
    As you can see, we generated unique string for the current LoadRunner virtual user. You can use it to save the current file, for example as "1_1_20080616_232322.940.pdf".

Summary:

Using of LoadRunner parameters is easy enough.
LoadRunner provides several useful types of parameters. We used three of them:
  • Vuser ID
  • Iteration Number
  • Date/Time
Also, this way doesn't require strong programming knowledge. The code is small and compact (in our script it consists of 1 line).

Simple and useful!



Related articles:


Have you got interested materials or your own thoughts on LoadRunner?
Let's share them and help each other to improve our skills and knowledge!
You can send them to my email: Dmitry Motevich's email

Thank you in advance, dear readers.

--
Dmitry Motevich

QTP - Capturing tool tips of images

In my previous post (QTP - How to capture tool tip?) I shown an example on capturing tool tip of Web page link.
That solution uses FireEvent("onmouseover") and GetROProperty("text") to get tool tip of a link.


Now, I'm going to show how to show how to capture tool tips of images located on a Web page.

Actually, the solution is simple.
To capture a tool tip of an image, we can get value of "alt" Run-time Object property with GetROProperty("alt") function:
Browser("brw").Page("pg").GetROProperty("alt")

Let's verify this code in practice. For example, let's check tooltips from Wikipedia Main page:

I've prepared QTP script, which gets all image from this page and checks their tooltips ("alt" property):
Dim descImage, listImages, attrAltText, attrSrcText

Browser("Main Page - Wikipedia,").Sync
Browser("Main Page - Wikipedia,").Page("Main Page - Wikipedia,").Sync

' Create description for all images on a Web page.
' For that we use "html tag" property and its value "IMG"
Set descImage = Description.Create
descImage("html tag").value = "IMG"

' Get all images which match the above description
Set listImages = Browser("Main Page - Wikipedia,").Page("Main Page - Wikipedia,").ChildObjects(descImage)

' Check tool tips of images
For i = 0 To listImages.Count - 1
    attrAltText = listImages(i).GetROProperty("alt")
    attrSrcText = listImages(i).GetROProperty("src")

    If attrAltText <> "" Then
        MsgBox "Image src: " & attrSrcText & vbNewLine & "Tool tip: " & attrAltText
    End If
Next

When I run this code in QTP, it shows all images containing non-empty tool tip:
(click the image to enlarge it)

The same message boxes will be shown for others images on a Web page.

So, our solution is simple - use GetROProperty("alt") function to get tool tip of image.
As you can see - it works correctly.


Related articles:


Do you like this QTP visual tutorial? Would you like to receive them in the future?
If yes, please subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)

--
Dmitry

How to save parameter value to other parameter in LoadRunner?

One my reader asked me - "How to save parameter value to other parameter in LoadRunner?". OK, there is a simple solution.

To save parameter value to other parameter you have to:
  1. Evaluate value of initial parameter
    Use lr_eval_string LoadRunner function.
  2. Save the evaluated string to a second parameter
    Use lr_save_string LoadRunner function.
Please, check the following code:
// save string value to initial parameter
lr_save_string("some string value", "prmStr1");
lr_output_message(lr_eval_string("Value of prmStr1: {prmStr1}"));

// save the evaluated value to second parameter
lr_save_string(lr_eval_string("{prmStr1}"), "prmStr2");
lr_output_message(lr_eval_string("Value of prmStr2: {prmStr2}"));
Let's execute this code and check the result:
(click the image to enlarge it)

As you can see, both parameters (prmStr1 & prmStr2) have the same values - "some string value".
So, we assigned the parameter value to other parameter successfully.


Related articles:


Do you have questions on this topic - working with LoadRunner parameters?
Feel free to post them in comments.

--
Dmitry