Showing posts with label Automated testing. Show all posts
Showing posts with label Automated testing. Show all posts

QTP Videos & LoadRunner Videos


HP QTP (QuickTest Professional) Videos:

1QTP video tutorial - How to record QTP scriptQTP video tutorial - How to record QTP script

The present QTP (QuickTest Pro) video tutorial covers the following:
  • How to record QTP script for Web applications
  • What record and run settings should be used to run and execute QTP script
  • How to replay/execute QTP script
  • How to get results of executed QTP script
  • How to enable capturing screenshots during QTP scipt replaying
  • How to enable capturing video during QTP scipt replaying
2QTP video tutorial - How to capture dynamic textQTP video tutorial - How to capture dynamic text

The present QTP (QuickTest Pro) video tutorial covers the following:
  • How to use QTP to capture text from the page
  • Settings from QTP 'Output Text Value Properties'
  • Explanation for QTP Output value
  • Explanation for left & right boundaries
  • How to save QTP Output text value into QTP DataTable
  • Differences between Global and Local QTP DataTable sheets
  • How to read value from QTP DataTable
3QTP video tutorial - QTP DatatableQTP video tutorial - QTP Datatable

This QTP video shows how to work with DataTable.
You will learn different QTP DataTable concepts:
  • How to create QTP DataTable parameter using QTP Data Driver
  • How to create QTP DataTable parameter manually
  • How to read/write values from/to QTP DataTable
  • QTP script and DataTable execution settings
  • Global and local (action) sheets of DataTable
  • QuickTest Professional data-driven tests
4QTP video tutorial - QTP RegExp and dynamic link in QTPQTP video tutorial - QTP RegExp and dynamic link in QTP

This QTP video tutorial covers the following:
  • working with QTP Object Repository
  • identification properties of QTP objects
  • QTP RegExp in object's properties
  • how QTP identifies objects in application
  • and others...
5QTP video tutorial - QTP Descriptive ProgrammingQTP video tutorial - QTP DP (Descriptive Programming)

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
6QTP video tutorial - How to run QTP test from command lineQTP video tutorial - How to run QTP test from command line

Do you run your QTP tests suit manually?
What about running them on the schedule, for example nightly testing?

I will show the way how to do that - i.e. how to run QTP tests from command line.
Using that approach, you can execute your QTP tests on the schedule.
7QTP video tutorial - QTP Recovery ScenarioQTP video tutorial - QTP Recovery Scenario

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 these events.

QTP provides Recoverry Scenarios to process such unexpected events and errors.


HP LoadRunner Videos:
1LoadRunner video tutorial - Automated Correlation in LoadRunnerLoadRunner video tutorial - Automated Correlation in LoadRunner

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
2LoadRunner video tutorial - Manual Correlation in LoadRunnerLoadRunner video tutorial - Manual Correlation in LoadRunner

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 LoadRunner correlation manually
  • How to use LoadRunner correlation functions
3LoadRunner video tutorial - LoadRunner Parameters, part #1LoadRunner video tutorial - LoadRunner Parameters,
part 1 of 3 (Select next row = Sequential)


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
4LoadRunner video tutorial - LoadRunner Parameters, part #2LoadRunner video tutorial - LoadRunner Parameters,
part 2 of 3 (Select next row = Random)


The present LoadRunner video tutorial covers the following:
  • How to create new LoadRunner parameter
  • Settings on Parameter List dlg:
    Option 'Select next row' = 'Random'
    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
5LoadRunner video tutorial - LoadRunner Parameters, part #3LoadRunner video tutorial - LoadRunner Parameters,
part 3 of 3 (Select next row = Unique)


The present LoadRunner video tutorial covers the following:
  • Settings on Parameter List dlg:
    Option 'Select next row' = 'Unique'
    Option 'Update value on' = 'Each iteration'
    Option 'Update value on' = 'Each occurrence'
    Option 'Update value on' = 'Once'Option 'When out of values' = 'Abort Vuser'Option 'When out of values' = 'Continue in a cyclic manner'Option 'When out of values' = 'Continue with last value'
    'Allocate Vuser values in the Controller'
  • How to view an output value of LoadRunner parameter
6LoadRunner video tutorial - How to capture the whole Web pageLoadRunner video tutorial - 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.
7LoadRunner video tutorial - How to record a file saving in LoadRunnerLoadRunner video tutorial - How to record a file saving in LoadRunner

In some cases, we need to save PDF (or other) file on local disk and process it (edit, parse, or compare with 'etalon' file).

The present LoadRunner video tutorial explains how to record PDF file saving in LoadRunner.
8LoadRunner video tutorial - How to check a downloaded fileLoadRunner video tutorial - How to check a downloaded file

Do you know how to check that a file or a page was downloaded successfully in LoadRunner?
The present LoadRunner video tutorial explains how to do that.

There is an easy and practical approach.


Dear readers, as you can see, I performed a huge work to prepare these videos.
In general, it took me ~ 60 hours for each video:
  • to think up examples (they should be simple)
  • to develop a scenario of video tutorial (I prefer logical and 'step-by-step' scenarios)
  • to record video (actually, not easy task)
  • to make, edit, check and recheck, and then again to remake movie (it should be ideal!)

I think, that my readers should get the perfect QTP and LoadRunner video tutorials. And I create such video tutorials.
That's why I ask you to help me - please, make donations. Your donation will mean that my videos were useful fot you and I'll be glad that you learnt something new.

It will motivate me to make new, even better videos!






Related articles:

--
Dmitry Motevich

15 QTP sites/blogs/groups/forums


1QTP on Easy way to automate testingQTP on Easy way to automate testing

There are a lot of QTP videos. Each QTP text tutorial contains screen shots.
So, this is a well-illustrated blog containing interesting info for QTP newcomers and professionals.
You can find here different QTP videos and tutorials. Example QTP video #1, #2, #3, #4, etc.
To get new QTP videos and articles automatically, you can subscribe to blog.
2QTP Google groupQTP Google group

This is a moderated QTP group. A great place for newcomers and professionals to improve knowledge and experience in QTP.
This is a very big QTP group - more than 1250 members as at Jan 19th, 2009. So all issues will be resolved quickly.
You can subscribe to this group here.
Before posting, please read Rules, FAQ, and others pages.
3
Quality Center on HP ForumsQuality Center on HP Forums

Office HP forum for all questions related to HP Quality Center.
Unfortunately, there is no subbranch of QTP-related questions.
There are a lot highly professional specialists on this forum, so visit this forum from time to time to improve your professional skills.
4
QTP on sqaforumsQTP on SQAForums

This is a QTP branch of SQAforums site. Moderated forums where you can find solutions to different QTP questions.
As a bonus, several HP QTP Support engineers share their knowledge and experience.
Before posting, please read forum guidelines.
5AdvancedQTP siteAdvancedQTP site

Great site containing unique and interesting information about QTP.
Authors publish periodically articles about non-documented QTP features, investigations, books, etc.
Site contains internal forum.
6KnowledgeInbox by Tarun LalwaniKnowledgeInbox by Tarun Lalwani

Tarun Lalwani is well-known in QTP global community as a highly professional QTP engineer.
His site contains a lot of artciles about different QTP features and topics - Descriptive Programming, VBScript, and even original QTP tools.
7
Software Iinquisition siteSoftware Iinquisition site

Amazing site! Definetely, you will like their simple and clear QTP articles.
Authors (Marcus Merrell & Will Roden) describe parts of their Software Inquisition Foundation Library for QTP (a kind of QTP Framework), and many others interesting things.
8
Stefan Thelenius' blogStefan Thelenius' blog

Don't want to waste your time developing and implementing Test Automation report, Test Suite Driver Script, and others interesting things? Read Stefan's blog.
9HP QuickTest Professional Software siteHP QuickTest Professional Software site

Official HP QTP's site.
There is a lot of related information - documentation, demos, guides, downloads, news, and so on.
10
'Automated Chaos' blog'Automated Chaos' blog

The blog does not contain too many QTP articles, but all of them are interesting and unique.
Use this practical experience to save your time while debugging your QTP script or implementing QTP framework.
11Ankur Jain's blogAnkur Jain's blog

Yet another great blog about QTP and QTP-related issues. Ankur has the ability to describe complex things in simple terms.
Also, it's possible to ask questions in comments or on local forum.
12Theo Moore's blogTheo Moore's blog

Theo Moore is a man who knows everything :)
As for QTP, readers will find different articles to extend their theoretical knowledge and improve their practical experience.
13HP Advanced Self-Solve Knowledge SearchHP Advanced Self-Solve Knowledge Search

'Knowledge Base' of QTP-related articles, manuals, documents, webinars, and others extremely useful documents.
Many artciles contains 'must know' technical information. Greate place to prepare for QTP certifications.
This site requires HP login.
14QTP on tdforumsQTP on TDForums

There is another good forum about QTP. Also, TDForum contains great info about working and tuning of Quality Center.
Site requres registration from corporate (not public) email account.
15
Mohan Kumar Kakarla's QTP blogMohan Kumar Kakarla's QTP blog

Site contains QTP scripts which can be a core of QTP Functions library. Real-life examples.

Note: I understand that this list of QTP sites is not complete and ideal.
It only expresses my own opinion.

I would be thankful if you shared your favorite QTP Internet sources to expand the present list.
So, feel free to send them to me:
Dmitry Motevich's email

--
Dmitry Motevich



Related articles:


Do you like this QTP Sites List? 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 like this QTP tutorial?
Feel free to use/copy/publish all my materials on your site/blog!


QTP DataTable - QTP video

This QTP video shows how to work with DataTable.
You will learn different QTP DataTable concepts:
  • How to create QTP DataTable parameter using QTP Data Driver
  • How to create QTP DataTable parameter manually
  • How to read/write values from/to QTP DataTable
  • QTP script and DataTable execution settings
  • Global and local (action) sheets of DataTable
  • QuickTest Professional data-driven tests
There is a sample screenshot from the present QTP video:


QTP DataTable - QTP video


Dear reader! Would you like to get new QTP videos?
Please, suggest new topics! What videos would you most interested in?

Also, I will be grateful for any shared information about QTP and others automated testing tools.

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 like this QTP tutorial?
Feel free to use/copy/publish all my materials on your site/blog!


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?