Showing posts with label visual tutorials. Show all posts
Showing posts with label visual tutorials. Show all posts

QTP DP (Descriptive Programming) - QTP video

QTP DP (Descriptive Programming) allows working without native QTP Object Repository. QTP Descriptive Programming provides test objects' properties and their values.
So, QTP uses Descriptive Programming statements to identify objects in AUT (application under test) during Run-time.

This QTP video shows and explains concepts of QTP Descriptive Programming:
  • What is QTP Descriptive Programming?
  • How to pass properties and their values directly to test object?
  • How to pass properties and their values using Description object?
  • How to select Descriptive Programming properties of a test object?
  • How t0 oconvert usual QTP script into QTP Descriptive Programming script?
  • How to debug QTP DP?
  • Different secrets of QTP Descriptive Programming
There is a sample screenshot from the present QTP video:
QTP DP (Descriptive Programming) screenshot

QTP DP (Descriptive Programming) - QTP video


Dear reader!
As usual, I need your help :)

Do you have ideas about new video tutorials? Could you suggest new topics? What videos would you most interested in?
Please remember - The content of this blog depends on your wishes and creative ideas!

So, feel free to cantact me.
My email is: Dmitry Motevich's email

--
Dmitry Motevich


Related articles:


Do you like this QTP Video 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


QTP Hackers - How to decrypt encrypted (SetSecure'd) password

I will explain you how to decode an encoded password in QTP.
Using QuickTest Professional and this approach, you can hack email accounts published on Internet. Are you interested? :) So, continue reading this QTP tutorial for details.

I've just recorded a simple script, which signs into Gmail. It:
  1. Fills 'Username' in
  2. Fills 'Password' in
  3. Clicks 'Sign in' button
Gmail screen
And the recorded QTP script is:
Browser("Gmail").Page("Gmail").WebEdit("Email").Set "someaccount"
Browser("Gmail").Page("Gmail").WebEdit("Passwd").SetSecure "493844a99bee0e3ab952f2e867fd08e3"
Browser("Gmail").Page("Gmail").WebButton("Sign in").Click

As you can see, QTP script is simple enough.
I've set "someaccount" to 'Username' editbox. But what about 'Password' editbox? What value have I filled in?


QTP encrypted the password using SetSecure method:
WebEdit("Passwd").SetSecure "493844a99bee0e3ab952f2e867fd08e3"
QTP Help:
The SetSecure method is recorded when a password or other secure text is entered.
The text is encrypted while recording and decrypted during the test run.


How to know the initial text?

There is one trick. Apply SetSecure method to non-secured edit box!
Instead of this QTP code:
Browser("Gmail").Page("Gmail").WebEdit("Email").Set "someaccount"
Browser("Gmail").Page("Gmail").WebEdit("Passwd").SetSecure "493844a99bee0e3ab952f2e867fd08e3"
I run this QTP script:
Browser("Gmail").Page("Gmail").WebEdit("Email").SetSecure "493844a99bee0e3ab952f2e867fd08e3"
And the result of this QTP script is:
Revealed PasswordYes, "mypwd" was encrypted to "493844a99bee0e3ab952f2e867fd08e3". So, "mypwd" is the password I filled!
So, this is an easy way to decrypt an encrypted password in QTP.


By the way, there are two ways how to decrypt a password in QuickTest Professional:
  1. Using Crypt.Encrypt
    str = "Some Text"
    encrStr = Crypt.Encrypt(str)

    'encrStr' will contain an encrypted text.

  2. Using Password Encoder from 'Start/Programs/QuickTest Professional/Tools'
    QTP Password Encoder
Summary:
  • I explained two ways how to crypt a text in QTP
  • I shown an approach how to decrypt an encrypted text


Well, I promised to show how to hack email addresses... I remember!

I searched several QTP sites and forums for "SetSecure" function and found that some QTP engineers published their code snippets with encrypted passwords (for example, entrance into email accounts) :)

Now you know how to "read" (=steal) passwords in plain text.

Why do I tell that?
Just to remind - be careful when you publish such private info on Internet.

--
Dmitry Motevich



Related articles:


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




Do you know that you are free to use/copy/publish all my materials on your site/blog?


QTP - How to get all Object Indentification Properties?

There are two ways how to get all properties of an object in QuickTest Professional:
  1. Manually
  2. Programmatically
Use QTP Object Spy to get manually object properties.
I've captured properties of ''Advanced Search" link from Google's page:
So, QTP Object Spy shows these values:
QTP Spy ObjectUsing QTP Object Spy you can get Run-time Object Properties and Test Object Properties.
It's possible to get these properties programatically:
  • The GetTOProperty and GetTOProperties methods enable you to retrieve a specific property value or all the properties and values that QuickTest uses to identify an object.
  • The GetROProperty returns the current value of the test object property from the object in the application.

GetTOProperty differs from the GetROProperty method:
  • GetTOProperty returns the value from the test object's description.
    Test Object Properties are stored in the QTP Object Repository.
  • GetROProperty returns the current property value of the object in the application during the test run.
    QTP reads Run-time Object Properties from actual objects during the runnins can be read and accessed during the run session.

That means that when you work with objects using QTP Descriptive Programming (DP), you will be able to access run-time object properties only (using GetROProperty function). Test object properties (using GetTOProperty function) will not be accessed, because QTP DP doesn't work Object Repository.

There is a problem with Run-time object properties.
In contrast to GetTOProperties (which returns the collection of all properties and values used to identify the test object), GetROProperties function does NOT exist!
Once again - GetROProperties function does NOT exist!


Well, how to get all Object Indentification Properties of an object?
Answer:
We can read them from Windows Registry.

The following registry key contains properties of a given test object:
HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\_Test_Object_\Properties

For example, I've opened:
HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Link\Properties and I've got properties of Link object:

Please note that you can find the same Link Identification Properties in QuickTest Professional Help:
Link Indentification Properties from QuickTest Professional Help
QTP Object Identification Properties can be used:
  • in the object repository description
  • in programmatic descriptions
  • in checkpoint and output value steps
  • and as argument values for the GetTOProperty and GetROProperty methods

So we have to read all Identification Properties from the registry.
This QTP code reads Link Identification Properties:
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

sKeyPath = "SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Link\Properties"
oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyPath, arrNames


As a result, arrNames array contains all names of properties.
To prove my words I use this QTP script:
sNames = "Identfication Properties:" & vbNewLine

For
i = 0 to UBound(arrNames)
    sNames = sNames & arrNames(i) & vbNewLine
Next

MsgBox
sNames
The result is:
Compare these Link Identification Properties with properties from the registry. They are the same!

So, we can read names of properties.

Next step is to read their values. It can be archived using GetTOProperty or GetROProperty.
Also, I'm going to show how GetTOProperty and GetROProperty work for Test Object (located in QTP Object Repository) and Run-time Object (actual object, created during the run session).

  1. Properties of Test Object
    QTP script is:
    ' Link("Advanced Search") is an object from QTP Object Repository
    Set TestLink = Browser("Google").Page("Google").Link("Advanced Search")

    sNamesTO = "GetTOProperty for Test Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine
    sNamesRO = "GetROProperty for Test Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine

    For i = 0 to UBound(arrNames)
        sNamesTO = sNamesTO & arrNames(i) & ": " & TestLink.GetTOProperty(arrNames(i)) & vbNewLine
        sNamesRO = sNamesRO & arrNames(i) & ": " & TestLink.GetROProperty(arrNames(i)) & vbNewLine
    Next

    MsgBox sNamesTO
    MsgBox sNamesRO
    • Test Object Properties of Test Object
      Test Object Properties of Test Object and their values are:
      Test Object Properties for Test Object
    • Run-time Object Properties of Test Object
      Run-time Object Properties of Test Object and their values are:
      Run-time Object Properties for Test Object

  2. Properties of Run-time Object
    QTP script is:
    ' Link("text:=Advanced Search") is a dynamic run-time object
    Set TestLink = Browser("Google").Page("Google").Link("text:=Advanced Search")

    sNamesTO = "GetTOProperty for Run-time Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine
    sNamesRO = "GetROProperty for Run-time Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine

    For i = 0 to UBound(arrNames)
        sNamesTO = sNamesTO & arrNames(i) & ": " & TestLink.GetTOProperty(arrNames(i)) & vbNewLine
        sNamesRO = sNamesRO & arrNames(i) & ": " & TestLink.GetROProperty(arrNames(i)) & vbNewLine
    Next

    MsgBox sNamesTO
    MsgBox sNamesRO
    • Test Object Properties of Run-time Object
      Test Object Properties of Run-time Object and their values are:
      Test Object Properties and their values of Run-time ObjectWhy almost all properties are empty?

      As I said, GetTOProperty function gets values from Test Object, which is stored in QTP Object Repository. Since Run-time Object is a dynamic object, it's not stored in QTP Object Repository. That's why GetTOProperty function cannot read object's properties.

      Look at the above screenshot again. The only one property ('text') contains its value ('Advanced Search'). We used this property to create description for our link:
      Set TestLink = Browser("Google").Page("Google").Link("text:=Advanced Search")
      That's why this Run-time Object contains the only property.

    • Run-time Object Properties of Run-time Object
      Run-time Object Properties of Run-time Object and their values are:
      Run-time Object Properties of Run-time ObjectAs you can see, we got the same Run-time Object Properties both for Test Object and for Run-time Object. I can explain it.
      During the run session, QTP creates a Run-time copy of Test Object. That's why Run-time Object Properties were the same for Test Object and Run-time Object.

    Note: You can download final QTP script here.
--
Dmitry Motevich


Related articles:


How about automatic receiving such QTP tutorials?
Just subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)




Do you like this QTP visual tutorial? Feel free to place it on your site or blog.


4 ways to get & count objects in QTP

Imagine simple and practical QTP tasks:
  • How to count all links on Web page?
  • How to get them and click each link?
  • How to get all WebEdits and check their values?

I'm going to show 4 approaches how to get lists of UI controls and process them (for example get their count).
As an example, I will work with links on Google Labs page. My goal is to get the list of links and count them.

I've added Google Labs page to my Object Repository and now it looks like:
I use Object Repository (OR) to simplify my demo-scripts.
Since the browser & the page were added to OR, we can use them later like:
Browser("Google Labs").Page("Google Labs").

Now we are ready to start!

  1. QTP Descriptive Programming (QTP DP) and ChildObjects QTP function
    The approach uses Description object, which contains a 'mask'
    for objects we would like to get.
    QTP script is:
    Set oDesc = Description.Create()
    oDesc("micclass").Value = "Link"
    Set
    Links = Browser("Google Labs").Page("Google Labs").ChildObjects(oDesc)
    Msgbox "Total links: " & Links.Count
    The result of this QTP script is:
    ChildObjects returns the collection of child objects matched the description ("micclass" is "Link") and contained within the object (Page("Google Labs")).


  2. Object QTP property and objects collections
    QTP can work with DOM:
    Set Links = Browser("Google Labs").Page("Google Labs").Object.Links
    Msgbox "Total links: " & Links.Length
    I use Object property of Page object. It represents the HTML document in a given browser window.
    This document contains different collections - forms, frames, images, links, etc.
    And we use Length property to get the number of items in a collection.

    The result is the same as for the previous QTP script:


  3. Object QTP property and GetElementsByTagName method
    Again, we can get access to
    the HTML document and use its GetElementsByTagName method.
    As the name says,
    GetElementsByTagName method returns a collection of objects with the specified tag.
    Since we are going to get all link, we should use "a" tag.

    QTP script is:

    Set Links = Browser("Google Labs").Page("Google Labs").Object.GetElementsByTagName("a")
    Msgbox "Total links: " & Links.Length
    The result is the following:

    Note: There is another way how to select objects by tag name:
    Set Links = Browser("Google Labs").Page("Google Labs").Object.all.tags("a")
    Msgbox "Total links: " & Links.Length
    The result will be the same. 69 link will be found.


  4. XPath queries in QTP
    The idea of this approach is to use XPath queries on a source code of Web page.
    For example, "//a" XPath query returns all "a" nodes (= links) from XML file.

    There is one problem. Web page contains HTML code, which looks like XML code but actually it is not.
    For example:
    • HTML code can contain unclosed img or br tags, XML code cannot.
    • HTML code is a case-insensitive markup language, XML is a case-sensitive markup language, etc
      More details here.

    So, we have to convert HTML source code into XML. The converted code is named as XHTML.

    You can convert HTML documents into XHTML using an Open Source HTML Tidy utility.
    You can find more info about how to convert HTML code into XHTML code here.

    I will use the final QTP script from this page, a bit modified:

    ' to get an HTML source code of Web page
    HtmlCode = Browser("Google Labs").Page("Google Labs").Object.documentElement.outerHtml

    ' save HTML code to a local file
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.CreateTextFile("C:\HtmlCode.html", True, -1)
    f.Write(HtmlCode)
    f.Close()

    ' run tidy.exe to convert HTML to XHTML
    Set oShell = CreateObject("Wscript.shell")
    oShell.Run "C:\tidy.exe --doctype omit -asxhtml -m -n C:\HtmlCode.html", 1, True ' waits for tidy.exe to be finished

    ' create MSXML parser
    Set objXML = CreateObject("MSXML2.DOMDocument.3.0")
    objXML.Async = False
    objXML.Load("C:\HtmlCode.html")

    XPath = "//a" ' XPath query means to find all links
    Set Links = objXML.SelectNodes(XPath)
    Msgbox "Total links: " & Links.Length
    Note: you can download tidy.exe here for above QTP script.

    This QTP script leads to the same results - 69 links found:
    (Click the image to enlarge it)


  5. Bonus approah
    Why don't you count all Wen page objects manually? :) Open a source code of the page and start counting :)
    Just joking :)

Summary:
  • I shown 4 practical approaches how to count Web page links.
    Similarly you can process images, webedits, etc
  • Each approach gets a list of objects.
  • First approach (QTP DP + ChildObjects) is the most easy
  • Second & third approaches (Object + collections; Object + GetElementsByTagName) will work on Internet Explorer, because they use DOM methods
  • Fours approach is biggest but it is more powerful. It allows to use complex XPath queries.


Related articles:


Do you like this QTP 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


Manual Correlation in LoadRunner - Video

In previous LoadRunner video (Automated Correlation in LoadRunner) I shown how to use Automated Correlation. The present LoadRunner video explains how to manually correlate dynamic values:
  • How to find dynamic values in a server response
  • How to correlate them in LoadRunner
  • How to verify the correlation
There is a screenshot from the present LoadRunner video:
Manual Correlation in LoadRunner

Automated Correlation in LoadRunner - Video

Correlation is a key concept of HP LoadRunner. The present LoadRunner video tutorial explains how to correlate dynamic values in LoadRunner automatically:
  • How to find dynamic values to be correlated
  • How to compare recorded & replayed dynamic values
  • How to correlate them in LoadRunner
  • How to verify correlation
There is a screenshot from the present LoadRunner video:
Different server responses
Also, this LoadRunner video explains concepts of Correlation and how Correlation works.
Video tutorial demonstrates LoadRunner Correlation by the example of HP Web Tours application, which is shipped with LoadRunner. So, you can repeat and learn all shown actions yourself.

Automated Correlation in LoadRunner - Video


Related articles:


Do you like these LoadRunner video? 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)



Do you
know that you are free to use/copy/publish all my materials on your site/blog?


LoadRunner video - How to check manually a downloaded file

Do you know how to check that file or page was downloaded successfully in LoadRunner?
The present LoadRunner video tutorial explains how to do that. All you need is to check LoadRunner snapshot files (inf-files) located in LoadRunner script folder:
LoadRunner script files
LoadRunner video - How to check manually a downloaded file




Related articles:


Do you like this LoadRunner video 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


LoadRunner video - How to capture the whole Web page?

This LoadRunner video tutorial shows how to capture Web page.
Using this approach, you can get HTML source code of any Web page and then downloade it to a local file.

LoadRunner video - How to capture the whole Web page?


There is a final LR script for capturing and saving Web page:
int hFile;
char *szFileName = "c:\\page.html";

//Mark that we will capture the whole body of Web page
//Note: Mark that web_reg_save_param should be placed *before* web_url
web_reg_save_param("prmPage", "LB=", "RB=", "Search=Body", "RelFrameID=1", LAST);

web_url("labs.google.com", "URL=http://labs.google.com/", LAST);

//Web page has been captured, so print it out
lr_output_message("Page is: \r\n%s", lr_eval_string("{prmPage}"));

//Truncate to zero length or create file for writing.
if ((hFile = fopen(szFileName, "wb")) == NULL)
{
    lr_error_message("Cannot open %s", szFileName);
    return LR_FAIL;
}

//Write captured Web page to an output file
fprintf(hFile, "%s", lr_eval_string("{prmPage}"));

//Close the file pointer.

fclose(hFile);


Related articles:


Do you like this LoadRunner video 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)



How to update XML file from QTP

In previous QTP tutorial I shown how QTP can read data from XML file.
Today I will explain how to update XML data from QTP.

We will use this XML file:
Initial XML fileNote: You can download this XML file here.

Let's check how to update different values in above XML file:
  1. How to rename the title of first book?
    The QTP script is:
    Const XMLDataFile = "C:\TestData.xml"
    Const XMLNewFile = "C:\TestData2.xml"

    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
    xmlDoc.Async = False
    xmlDoc.Load(XMLDataFile)


    ' update the title of the first book
    Set node = xmlDoc.SelectSingleNode("/bookstore/book[0]/title")
    node.Text = "Romeo and Juliet - Salvation"

    ' save changes

    xmlDoc.Save(XMLNewFile)
    And the result is:
    Note: The numeration begins from zero. That's why I use book[0] to access first item.


  2. How to change the year of second book?
    I skip the opening and saving of XML file (see above QTP script). I show only the essence:
    ' update the attribute of the second book
    Set node = xmlDoc.SelectSingleNode("/bookstore/book[1]/title/@published")
    node.Text = "2009"

    And the result is:
    Note: Use @ to access an attribute of XML node.


  3. How to add new author add its new attribute?
    QTP script:
    ' select a parent node
    Set parentNode = xmlDoc.SelectSingleNode("/bookstore/book[2]")

    ' add a new author
    Set newNode = xmlDoc.CreateElement("author")
    newNode.Text = "Mr. Noname"
    parentNode.AppendChild (newNode)
    And the result is:
    As you can see, we've added "Mr. Noname" as the new author.


  4. How to add new attribute for author (XML node)?
    QTP script:
    ' select a parent node
    Set parentNode = xmlDoc.SelectSingleNode("/bookstore/book[2]")

    ' add its attribute
    Set newAttrib = xmlDoc.CreateAttribute("bestseller")
    newAttrib.Text = "yes"
    parentNode.Attributes.SetNamedItem(newAttrib)
    The result is:
    New attribute of a boof and its value ("bestseller"="yes") have been added.

Well, the working with XML files from QTP is easy enough.


Summary:
  • shown in QTP - how to change value of XML node
  • shown in QTP - how to change value of attribute
  • shown in QTP - how to add new XML node
  • shown in QTP - how to add new attribute


Do you have any comments, dear reader? Please, leave them below the present article.
Thank you in advance :)



Related articles:


Do you like this QTP 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


LoadRunner unique file name with web_save_timestamp_param function

Earlier, I shown two ways how to create unique file names in LoadRunner:

Today I'm going to show the simplest way. And I would like to thank Charlie for his comment.
He suggested to use web_save_timestamp_param function.

web_save_timestamp_param function saves the current timestamp to LoadRunner parameter. Timestamp is the number of milliseconds since midnight January 1st, 1970 (also known as Unix Epoch).

This is how web_save_timestamp_param works:
web_save_timestamp_param("TimeStamp", LAST);
lr_output_message("Timestamp: %s", lr_eval_string("{TimeStamp}"));

And the result is:
Results in LoadRunner Generator
As I explained in this loadRunner tutorial about unique file names in LoadRunner, we have to get unique ids per virtual users with lr_whoami LoadRunner function.

So, the final LoadRunner script is:
char szFileName[256];
int vuserid, scid;
char *groupid;

lr_whoami(&vuserid, &groupid, &scid); web_save_timestamp_param("TimeStamp", LAST);

sprintf(szFileName, "%s_%d_%d_%s",
    lr_eval_string("{TimeStamp}"),
    vuserid,

    scid,

    groupid);


lr_output_message("File name: %s", szFileName);
And its result is from LoadRunner Controller:
Results in LoadRunner ControllerSo, you can add a required file extension (txt, pdf, etc) and get a unique file name. It will work for any number of concurrent virtual users in LoadRunner Controller.


Summary:
  • Shown the way how to generate unique file names in LoadRunner
  • It uses web_save_timestamp_param function


Related articles:


Do you like this LoadRunner 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


QTP VBScript - Are you sure 1+1=2?

QTP VBScript contains different niceties. This article shows that 1 + 1 doesn't equal 2 sometimes.

Exactly, 1 + 1 doesn't equal 2 sometimes.

Well, I've prepared this QTP script:
n1 = InputBox("Enter first number")
n2 = InputBox("Enter second number")
n1increased = n1 + 1

If n1increased = n2 Then
    MsgBox n1 & " + 1 equals " & n2
Else
    MsgBox n1 & " + 1 doesn't equal " & n2
End If

I will explain it step by step and show all entered data and generated result.
  1. Read first number from user's input
    I enter 1 as a first number:
    First number = 1
  2. Read second number from user's input
    I enter 2 as a second number:
    Second value = 2
  3. Increase first number by 1
    n1increased = n1 + 1

  4. Check whether first increased number equals to second number
    If n1increased = n2 Then
        MsgBox n1 & " + 1 equals " & n2
    Else
        MsgBox n1 & " + 1 doesn't equal " & n2
    End If

    And the result is:
    The result of QTP script

Do you know why it is so? What is a reason?
The answer is simple. This is due to converting of VBScript types.

After you read first number (1) from user and assign it (value of course value, not user :) ) to variable, this variable has value of String type.
So, this is the same like n1 = "1"

When VBScript executes this line:
n1increased = n1 + 1
it sees, that we perform mathematical operation and converts n1 into number.
Then VBScript calculates n1 + 1 and the result (2) has a numeric type - Double (special double-precision floating-point value).

Here is the main point! 2 as Number is not the same as 2 as String. These values have different type and that's why they differ.
Simple visual example - two apples are not equal to two pears :)

I can demonstrate the above types converting.
I've added this code into our QTP script before if-then-else:
MsgBox "TypeName(n1): " & TypeName(n1)
MsgBox "TypeName(n1increased): " & TypeName(n1increased)
MsgBox "TypeName(n2): " & TypeName(n2)
And its result is:
Results of TypeNameThat's why the value of number variable is not equal to the value of string variable.


Well, How to make that 1 + 1 = 2 ?
Answer: Convert string value to number with CInt function:
If n1increased = CInt(n2) Then
    MsgBox n1 & " + 1 equals " & n2
Else
    MsgBox n1 & " + 1 doesn't equal " & n2
End If

And the result is:
Correct result of QTP scriptIt works. It works correctly :)

I hope, you will keep in mind this issue with VBScript types converting. It can save your time during debugging of QTP scripts.



Related articles:


Do you like this QTP 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


QTP Recovery Scenario VIDEO

This QTP video shows and explains how to create and work with QTP Recovery Scenarios.

For example, during an execution of QTP test, it can be interrupted by different windows, pop-ups, message boxes, etc. The problem is that they can appear at any time and you cannot predict this event.

I've shown how to create QTP Recovery Scenario for the following message box:
Message box in QTP
This message box can be shown or not, depending on the current system settings.
QTP provides Recoverry Scenarios to process such unexpected events and errors.


QTP Recovery Scenario VIDEO



Related articles:


Do you like this QTP video? 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)




Do you know that you are free to use/copy/publish all my materials on your site/blog?


QTP - How to rename Excel worksheet

The present QTP tutorial shows simple recipe how to rename Excel worksheet from QuickTest Professional.

For example, Excel-file contains 'Sheet1' sheet:
Initial worksheet

How to rename Excel worksheet from VBScript and QTP?

Use the following QTP script, which perform the work using Excel's COM object - "Excel.Application":
Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.DisplayAlerts = False

Set
objWorkbook = objExcel.Workbooks.Open ("c:\Book1.xls")

Set objWorksheet = objWorkbook.Worksheets(1)

objWorksheet.Name = "VBScript_Excel"

objWorkbook.SaveAs ("c:\Book1.xls")
objExcel.Quit

The above QTP script renames Excel worksheet:
Renamed worksheet

Summary:
  • Excel's COM object ("Excel.Application") allows performing operations on Excel application
  • The present visual tutorial explains how to rename Excel sheet from QTP


Related articles:


Do you
like this QTP visual tutorial? Would you like to publish it on your site/blog?
You are free to use/copy/publish all materials on your site/blog.


How to read XML file from QTP

I'm going to show how to parse XML file and read its values from QTP (QuickTest Professional).
For example, we will use this XML file:
This XML file describes a bookstore and books located there.
Note: You can download this XML file here.



I will use Microsoft's XML Parser also known as Microsoft.XMLDOM. This XML parser allows running XPath queries.

The loading of XML file in QTP is simple enough:
Const XMLDataFile = "C:\TestData.xml"

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
xmlDoc.Load(XMLDataFile)


Several comments on this code:
  1. Microsoft.XMLDOM is a name of COM object of Microsoft's XML parser
  2. Async is a property of Microsoft.XMLDOM.
    The property specifies whether asynchronous download of the document is permitted.
    Processing of asynchronous operations is more complex, that's why I've disabled it (xmlDoc.Async = False). For datailed info see here.
  3. Load method loads an XML document from the specified file.
    Also, you can use LoadXML method, which loads an XML document using the supplied string.

After that we can use SelectSingleNode or SelectNodes of Microsoft's XML parser to execute XPath query.
You can use this approach in QTP to get data from XML file.

Check the above bookstore XML file again and let's see:

  1. How to get number of books in a bookstore?
    The QTP script is:
    Set nodes = xmlDoc.SelectNodes("/bookstore/book")
    MsgBox "Total books: " & nodes.Length

    And its result is:
    Number of books in a bookstoreAs you can see, "/bookstore/book" XPath expression selects all "book" nodes in a "bookstore" nodes. As a result, we get the list of all books.

    I hope, that's clear. Let's complicate the task a bit.


  2. How to get titles of all books in a bookstore?
    QTP script gets list of books from XML file and iterates them through:
    ' get all titles
    Set
    nodes = xmlDoc.SelectNodes("/bookstore/book/title/text()")

    ' get their values
    For i = 0 To (nodes.Length - 1)
        Title = nodes(i).NodeValue
        MsgBox "Title #" & (i + 1) & ": " & Title
    Next

    The result is:
    Titles of all books

  3. How to get title of the first book?
    QTP script is:
    Set node = xmlDoc.SelectSingleNode("/bookstore/book[0]/title/text()")
    MsgBox "Title of 1st book: " & node.NodeValue
    Please see how QTP parses XML file and gets the required value:
    Title of the first bookNote: Pay attention that nodes are zero-indexed, i.e. first book is book[0], second book is book[1], and so on.


  4. How to get titles of all John Smith's books?
    QTP script is:
    ' get list of John Smith's books
    Set nodes = xmlDoc.SelectNodes("/bookstore/book/title[../author = 'John Smith']/text()")

    ' get their titles
    For i = 0 To (nodes.Length - 1)
        Title = nodes(i).NodeValue
        MsgBox "Title #" & (i + 1) & ": " & Title
    Next

    Note: We use square brackets to apply a filter. So, [../author = 'John Smith'] means 'to get only those books whose author is John Smith'.

    Since Mr. Smith wrote two books, we get the following result:
    Titles of John Smith's books

  5. How to get titles of all books published after 2003?
    QTP script is:
    ' get list of books published after 2003
    Set nodes = xmlDoc.SelectNodes("/bookstore/book/title[@published > 2003]/text()")

    ' get their titles
    For i = 0 To (nodes.Length - 1)
        Title = nodes(i).NodeValue
        MsgBox "Title #" & (i + 1) & ": " & Title
    Next

    Note: And again, we use square brackets to apply a filter - [@published > 2003].
    At sign (@) is used to address an attribute of a node. For example:
    Here, title node contains one attribute - published.
    So, [@published > 2003] means 'to get only those books which were published after 2003'.

    The result of above QTP script is:
    Titles of books published after 2003You can check initial XML file and make sure that QTP parses it correctly.

Summary:
  • Use Microsoft.XMLDOM to read and parse XML file from QuickTest Professional (QTP)
  • XPath allows creating different queries to extract required data
  • The present visual tutorial explains how to process XML file from QTP


Related articles:


Do you like this QTP 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 Motevich