Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

XML DOM and QTP - Using VBScript


The XML DOM (XML Document Object Model) defines methods for accessing and manipulating XML documents.This topic will discuss how to manipulate  XML  using  vbscript and accessing information from XML.

Methods to Access XML DOM:


1. Creating an object for xmlDOM

set  xmldom = Createobject("MSXML.DOMDocument")
xmldom.async = “False”

2. Loading a file using xml DOM


Xmldom.Load(FileName)

3. To Find number of parent nodes in a xml

Intlen = Xmldom.childnodes.length

4. To find names of parent nodes

For i=0 to intlen-1
      strParNodeName = xmldom.childnodes(i).Name
Next

5. How to search a node with tagName

Set nodelist = xmldom.getElementsByTagName(strTagName)

This gives a collection of nodes with tag name as strTagName.
The tagName value "*" will returns all elements in the document.

6. How to extract information from nodelist using GetElementbyTagName

Set nodelist = xmldom.getElementsByTagName(strTagName)
For i= 0 to nodelist.length – 1
       strText = nodelist.item(i).xml;
       msgbox strText
Next

So points to remember in this are as follows:


  • We can get all elements with the tagname using xmldom.getElementsByTagName

  • Once we have the list, we can access each of the nodes in the list using item(index).property

  • To access attribute property value for a node , use strText = nodelist.item(i).getattribute("category")

  • To get xml content of a node, use strText = nodelist.item(i).xml

  • Use strText = nodelist.item(i).nodeName to get the name of required node.

  • Use strText = nodelist.item(i).text to get value in a particular node


Sample Code explaining the concept


FileName = "d:\xmldom.xml"
''Create an instance of xml dom
set  xmldom = Createobject("MSXML.DOMDocument")
''set async = "False"
xmldom.async = "False"
xmldom.Load(FileName)
intlen = xmldom.childnodes.length
msgbox intlen
Set nodelist = xmldom.getElementsByTagName("title")
msgbox nodelist.length
If nodelist.length > 0 then
    For each x in nodelist
        AttName=x.getattribute("lang")
        myname = x.Text
        msgbox AttName +" "+ myname
    Next
Else
    msgbox " field not found."
End If

7. Using Selectnodes method to extract information


FileName = "d:\xmldom.xml"
''Create an instance of xml dom
set  xmldom = Createobject("MSXML.DOMDocument")
''set async = "False"
xmldom.async = "False"
xmldom.Load(FileName)
intlen = xmldom.childnodes.length
msgbox intlen
Set nodelist = xmldom.selectNodes("/bookstore/book/title")
msgbox nodelist.length
If nodelist.length > 0 then
    For each x in nodelist
        AttName=x.getattribute("lang")
        myname = x.Text
        msgbox AttName +" "+ myname
    Next
Else
    msgbox " field not found."
End If

8. Using SelectSingleNode to extract information


FileName = "d:\xmldom.xml"
''Create an instance of xml dom
set  xmldom = Createobject("MSXML.DOMDocument")
''set async = "False"
xmldom.async = "False"
xmldom.Load(FileName)
''This will give 1st item property matching the node structure
Msgbox xmldom.selectSingleNode("/bookstore/book/title").Text
''This will give 1st item property matching the node structure with filter as attribute value
Msgbox xmldom.selectSingleNode("/bookstore/book/title[@lang = 'ke']").Text
''This will give 1st item property matching the node structure with filter as text  value
Msgbox xmldom.selectSingleNode("/bookstore/book/title[.= 'Learning XML']").Text


Different Ways to do recording in QTP


Recording in QTP can be done in following modes:


Normal Recording


This is the default mode of recording in QTP. It records the objects in your application and the operations performed on them.During normal recording objects are identified as standard objects are saved in repository.

To Access Normal Recording, Click the Record button or select Automation > Record or press F3 Key.


Analog Recording Mode


This mode records the mouse movement and keyboard operation in the application.This mode is useful in case object is not recognized as standard object.

To Access Analog recording, start a recording session as we do in normal recording. Click the Analog Recording button or select Automation > Analog Recording to start analog recording.Once recording is complete, click the analog recording button to close analog recording.
The mouse and keyboard operation are saved in a track file which can be reused.The track file called by the RunAnalog method contains all your analog data and is stored with the current action.

Window("Microsoft Internet Explorer").RunAnalog "Track1"

Some useful points to remember about Analog recording are as follows:


1. Shortcut Key for Analog Recording is SHIFT+ALT+F3.

2. Useful for applications in which the actual movement of the mouse needs to be recorded.

3. Analog Recording can record relative to the screen or relative to a specific window. The settings are defined in Analog Recording Settings.

4. The steps are recorded in a separate file saved within the action.

5. Steps once recorded cannot be edited in Analog recording.

6. Test may fail in case screen resolution changes.


Low Level Recording


This enables user to record the exact coordinates of any object, whether or not QuickTest recognizes the specific object or the specific operation.

To Access Low Level recording, start a recording session as we do in normal recording. Click the Low level Recording button or select Automation > Low Level Recording to start analog recording.

Some useful points to remember about Analog recording are as follows:


1. Shortcut key for Low Level recording is CTRL+SHIFT+F3

2. Useful when object is not identified by QTP in normal recording mode.

3. During Low Level recording, objects and parent objects are added as window object.


Window("…").WinObject("…").Click 12,32


Object Identification in QTP - Learning Objects


During run time QTP matches the object properties it store during test preparation and perform the required action on the object identified.In this article, we will discuss how objects are identified in QTP.

Learning an Object


1. When we work on an object, QTP stores it as a test object and assign class to the object to which it belongs, For e.g: webEdit, WebElement.

2. QTP considers the mandatory identification property for the object based on the class to which the object belongs.

3. If it is not able to identify unique object in the page using mandatory properties, it adds assistive properties one by one until a unique identification is created.

4. It then adds ordinal identifier if identification properties (defined in 2 and 3) are not unique to identify object. Ordinal Identifier indexes the object based on Location, Creation time or index of the object in the page.

5. We can also define Visual relation identifier. Visual relation identifier defines an object based on relative position of the object relative to other objects in the page. For details on this, please refer QTP user guide.

6. We can also enable Smart Identification for the object in the object repository.


As explained in step 1-6 above, identification for object are created and saved in the object Repository.

An object can be learned in object Repository in following ways:

1. During recording session.

2. Using Object spy.

3. Learning from object repository Tool.


All the child objects can be learned based on the parent object using Object Spy.

Identification of object during run session:


Once we have learned the entire objects, an object repository containing all required objects is created.
During Run-session, QTP looks to identify unique object matching the object definition from object repository. Once it finds the required object, it performs action on particular object.

The object is identified during run session in following way:


1. It looks for identification properties (mandatory and assistive properties) in the run object.

2. In case more than one object matching the identification properties is found and visual relation identifier is defined, it search to identify the object using virtual relation identifier.

3. In case unique object is not found in step 1 and 2, QTP uses smart identification to identify the object.

4. In case using above steps, if object is not identified and virtual relation identifier is not defined, it looks for ordinal identifier properties.


Using above steps, QTP determines if the object is identified in QTP

Brief about Terms used:


Visual relation identifier

Visual relation identifier defines an object based on relative position of the object relative to other objects in the page.

Smart Identification

In case, QTP is not able to identify unique object based on identification properties and smart Identification checkbox is selected, it forgets learned properties and tries to identify the unique object based on Base Filter Properties and optional filter properties defined in smart identification. It searches for all objects matching the base filter properties and filter out objects based on optional filter property one by one, until a unique object is found.

Ordinal Identifier

The ordinal identifier assigns the object a numerical value that indicates its order relative to other objects with an otherwise identical description. Index, Location, and Creation time are different types of ordinal Identifier. Creation Time is browser specific only.