Wednesday, October 16, 2013

QTP GetROproperty and GetTOproperty


QTP GetROproperty and GetTOproperty
 
To better understand the concept of GetROproperty and GetTOproperty methods practically we can follow below steps:
1.       Start recording on QTP.
2.       Open Google.com page
3.       Click on “Google Search” button.
4.       The script will looks like following,
 
SystemUtil.Run “http://google.com/”,”",”",”"
Browser(“Google”).Page(“Google”).WebButton(“Google Search”).Click
Browser(“Google”).Close
 5.       To use “GetROproperty” Now modify the second statement to following,
Msgbox Browser(“Google”).Page(“Google”).WebButton(“Google Search”).GetROproperty(“name”)
 6.       Now run the above script, You will get msgbox which contains “Google Search” in it.
 
GetROproperty: This property is used to get the property of the object during runtime from the UI. In our case GetROproperty gets property of “name” object of “Google Search” webbutton.
 7.       Now copy the above statement and modify it to following,
Msgbox Browser(“Google”).Page(“Google”).WebButton(“Google Search”).GetTOproperty(“name”)
 8.       Now close your browser and comment out other code except above statement.
 9.       Run only above  GetTOproperty statement. You will again get msgbox which contains “Google Search” in it.
 
GetTOproperty: This property is used to get the property of the object during runtime from the Object repository. In our case GetTOproperty gets property of “name” object of “Google Search” webbutton which is already stored in QTP object repository.
 
Now hope you are more clear regarding GetROproperty and GetTOproperty methods in QTP. You are always welcome to share your thoughts or doubts in QTP.
If you like this article, You can subscribe through mail.
 

Tuesday, July 23, 2013

QTP Script for adding NewLine in MsgBox using Vb Script




Dim ctrlLink, objLink

Set ctrlLink = Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Link("Create an account")
Set objLink = ctrlLink.Object

sColor = objLink.currentStyle.color
sBackgrColor = objLink.currentStyle.backgroundColor
sFontSize = objLink.currentStyle.fontSize
sFontStyle = objLink.currentStyle.fontStyle
sFontFamily = objLink.currentStyle.fontFamily
sFontWeight = objLink.currentStyle.fontWeight

MsgBox "sColor :"&sColor &vbNewLine& "sBackgrColor :"&sBackgrColor &vbNewLine& "sFontSize :"&sFontSize &vbNewLine& "sFontStyle :"&sFontStyle &vbNewLine& "sFontFamily :"&sFontFamily &vbNewLine& "sFontWeight :"&sFontWeight 

Output of QTP newline:



I think it is bit simpler than we thought. :-)
 

QTP - How to get Background Color, Font Size/Color and Other Attributes of Controls

Today I faced some issues with the following task with QTP (QuickTest Professional) - how to get some attributes (such as: font size, font color, background color and so on) for any control on a web page?

Let's see ways how we can do it.

The Task: Get font size, font color, background color and others possible parameters from the gmail.com start page:
The solution:
  1. First of all, I tried to use GetROProperty method.
    I selected "Welcome to Gmail" label with QTP object spy and added them to Object Repository:



     Well, now I know the class of web control - Link.

    Then, I open QuickTest Professional Help, search for "Link Identification Properties" and see that there are not needed properties (font name, font color, size, ...).

    Help reading shown that it is possible to get needed properties for some objects, for example, for WebElement. Please, see "WebElement Identification Properties" from the QTP Help:

    Property Name: Description
    • background color: The link's background color.
    • color: The link's color.
    • font : The link's font. 
    • Height :The object's height (in pixels).

    So, these properties work correctly for Link. For example, the following code:
    Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Link("Create an account").GetROProperty("color")
    returns value #fff

    for "Can't access your account? " link:


    In terms of RGB (red-green-blue), the value #0000ff means that blue-color is enabled.
    It looks like truth :)

    This approach (GetROProperty method) has a limitation - it can be applied for some objects. In my case (I use Link object) this methods cannot be applied.

  2. currentStyle object!
    The main idea is to read:
    Link("SomeName").Object.currentStyle.someProperty
    For example, use:
    • color property to get the color of the text
    • backgroundColor property to get the backgroung color (behind the content of the object)
    • fontSize property to get the font size
    • fontStyle property to get the font style
    • fontFamily property to get the font family
    • fontWeight property to get the font weight
    • and so on

    Please, read more detailed info on properties of currentStyle object:

    So, I used this code in my QTP script:

    Dim ctrlLink, objLink

    Set ctrlLink = Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Link("Create an account")
    Set objLink = ctrlLink.Object

    sColor = objLink.currentStyle.color
    sBackgrColor = objLink.currentStyle.backgroundColor
    sFontSize = objLink.currentStyle.fontSize
    sFontStyle = objLink.currentStyle.fontStyle
    sFontFamily = objLink.currentStyle.fontFamily
    sFontWeight = objLink.currentStyle.fontWeight

  3. Result is: