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?


Top 40 Automated Testing Blogs - Nov 2008

At the end of October 2008 I invited my readers to send me their favorite Automated Software Testing blogs.

I would like to thank those readers who shared most interesting and useful blogs.
Great job, dear colleagues! :)

As a result, I'm glad to introduce the final list of Top 40 Automated Testing Blogs.

I sorted these blogs on the basis of:
  • PageRank (PR) - Google's view of the importance of a pag. The bigger, the better.
  • AlexaRank (AR) - Alexa's range of a site based on a traffic.The lower, the better.
  • TechnoratiRank (TR) - position of the blog among all Technorati blogs. The lower, the better.
  • Comments (Cmts) - number of comments for all articles posted during previous 3 months (Aug, Sep, Oct 2008). The bigger, the better.
  • Incoming links (Links) - number calculated by Yahoo Site Explorer. The bigger, the better.
Top 40 Automated Testing Blogs

# Site / Author PR AR TR Cmts Links
1
Google Testing Blog (various)
5
219028
47930
112
8507
2
Performance Tidbits Rico Mariani
5

113248
31
16924
3
Scott Barber's blog Scott Barber
4

72223

19683
4
Collaborative Software Testing Jonathan Kohl
5

404815

8838
5
Cem Kaner's blog Cem Kaner5



5077
6
Agile Testing Grig Gheorghiu
5
315063
205275
56
4393
7
James Bach’s blog James Bach
4

164842
44
14020
8
Creative Chaos Matthew Heusser
5
2306703
373134
54
7655
9
Advanced QTP (various)
4
620947
722230
79
8585
10
Corey Goldberg's blog Corey Goldberg
4
1282348
256345
142
3244
11
The Braidy Tester Michael J Hunter
5

437554
17
4692
12
Tester Tested! Pradeep Soundararajan
4
1195245
770942
99
3810
13
WilsonMar.com Wilson Mar
4
164760
512788

1431
14
Testing Hotlist Update Bret Pettichord
4
1657484
446540
11
7487
15
Test Obsessed Elisabeth Hendrickson
5
3148166
351547
6
2493
16
My Load Test Stuart Moncrieff
4
1009095
553587

921
17
Theo Moore's blog Theo Moore
3

80402532
9155
18
Thinking Tester Shrini Kulkarni
4
1427381
1052395
30
3482
19
Observations on software testing and quality Michael Bolton
4

1038615
11
3653
20
Quality through Innovation Adam Goucher
4
8063489
722230
11
3973
21
Easy way to automate testing Dmitry Motevich
3
675427
1038615
131
503
22
Software Testing Zone Debasis Pradhan
3
760191
906103
14
1461
23
JW on Test James Whittaker
3


71
1027
24
Mike Kelly's blog Mike Kelly
4

1038615
1
2757
25
Questioning Software Ben Simo
5
4064149
1285236
4
1679
26
London software testing news (various)
4
2598600
2593630
3
1937
27
Ankur Jain's blog Ankur Jain
2
478294
655996
9
281
28
Jeff Fry on Testing Jeff Fry
4
11028482
1214675
7
1565
29
The Software Inquisition (various)
3
1449194
1214675
7
886
30
90kts Tim Koopmans
2
1648922
600724
5
63
31
Test this Blog Eric Jacobson
3
9632080
3324847
27
716
32
Stefan Thelenius about Software Testing
Stefan Thelenius
3
5716662
1867832
5
916
33
LoadRunner Tips and Tricks Hwee Seong Tan
0
2422241
1214675
24
478
34
QuickTest Pro Mohan Kumar Kakarla
3
1884598
1211403
1
91
35
KnowledgeInbox Tarun Lalwani
2
1165000


121
36
Alexander Podelko's blog Alexander Podelko
3



490
37
Software Performance Engineering & Testing Charlie Weiblen
3
5451220
4978471

152
38
Software Testing Blog Unknown
2
2712832
2593630

430
39
Automated Chaos Bas M. Dam
2
5130521


148
40
Automated Web Test Meena
2
7702460
4697735
2
144

Note: You can download raw statistic of this list here.

I know for sure - authors of these blogs did an excellent job. Thank you very much!

Note: I understand that nothing is constant. And this list of Automated Testing Blogs should be updated periodically. Also I'm sure that some cool blogs are not present on this list.

That's why I need to know your opinions. Do you have something to add? Please share.

Dear reader, do you have interesting ideas for such future lists, surveys, actions? What posts would you like to see here? Let me know please.
My email is: Dmitry Motevich's email

--
Dmitry Motevich




Related articles:



I recommend to subscribe to my blog and you will receive updates automatically.
You can subscribe to this blog RSS feed or by Email. (How to subscribe? Video guide)



Would you like to publish this Top 40 Automated Testing Blogs List on your site or blog?
Please know that
you are free to use/copy/publish all my materials.


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?