Piece of cake! :)
Let's see ways how it can be done.
The task: get font size, font color, background color and others possible parameters from the gmail.com start page:
- 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 - WebElement.
Then, I open QuickTest Professional Help, search for "WebElement 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 Link. Please, see "Link 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.
So, these properties work correctly for Link. For example, the following code:
Browser("Welcome to Gmail").Page("Welcome to Gmail").Link("About Gmail").GetROProperty("color")
returns value #0000ff for "About Gmail" 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 WebElement object) this methods cannot be applied.
Thanks to Mr. Google :) It found an appropriate solution:
- currentStyle object!
The main idea is to read:
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 ctrlWebEl, objWebEl
Set ctrlWebEl = Browser("Welcome to Gmail").Page("Welcome to Gmail").WebElement("Welcome to Gmail")
Set objWebEl = ctrlWebEl.Object
sColor = objWebEl.currentStyle.color
sBackgrColor = objWebEl.currentStyle.backgroundColor
sFontSize = objWebEl.currentStyle.fontSize
sFontStyle = objWebEl.currentStyle.fontStyle
sFontFamily = objWebEl.currentStyle.fontFamily
sFontWeight = objWebEl.currentStyle.fontWeight Result is:
- The last thing I have to do is to get a numerical value of background color.
For that I recorded another object - WebElement("corner_tl"):
- Note: when recording, click at the right of "Welcome to Gmail" text.
I executed my QTP script for that WebElement and got results:
Background color is #c3d9ff
Now, I think, mission is completed :)
All attributes (font size/color/weight, backgroung color) are gathered.
- Enjoy QuickTest Professional :)
- QTP - How to set/get system time and date?
- How to execute QTP script from LoadRunner?
- QTP - How to get font size/color, background color and other attributes of controls
- How to minimize/maximize QTP window before the QTP script execution?