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: