Escolar Documentos
Profissional Documentos
Cultura Documentos
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:
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:
There is one problem. Web page contains HTML code, which looks like XML code but actually it is not.
For example:
o HTML code can contain unclosed img or br tags, XML code cannot.
o 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
Answer: QTP DP is a run-time processing of objects which are not located in QTP Object Repository.
I've created new QTP script which starts with http://labs.google.com/sets page.
This QTP script is simple enough:
Set Desc = Description.Create()
Desc("micclass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)
As you can
see, it works correctly and returns correct number of Edits on a page.
I'm going to explain this QTP script and answer the following question:
To specify that we want identify all Edits on browser's page I use "micclass" property:
Desc("micclass").Value = "WebEdit"
Note: the "mic" prefix in "micclass" stands for "Mercury Interactive Constant".
Since we created Description object for all edit boxes, we can use this description to get all specified objects ( = edit
boxes).
The next step returns the collection of all child objects (i.e. edit boxes) contained within the page:
Set Links = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)
To get the number of found objects in a returned collection, we use Count property:
MsgBox "Number of Edits: " & Links.Count
Also, we can use the same code to get number of others objects - Links, Images, Buttons, etc.
For that I modified QTP script:
Function GetAllSpecificControls(Page, MicClass)
Set Desc = Description.Create()
Desc("micclass").Value = MicClass
Set GetAllSpecificControls = Page.ChildObjects(Desc)
End Function
Function GetAllEdits(Page)
Set GetAllEdits = GetAllSpecificControls(Page, "WebEdit")
End Function
Function GetAllButtons(Page)
Set GetAllButtons = GetAllSpecificControls(Page, "WebButton")
End Function
Function GetAllLinks(Page)
Set GetAllLinks = GetAllSpecificControls(Page, "Link")
End Function
Function GetAllImages(Page)
Set GetAllImages = GetAllSpecificControls(Page, "Image")
End Function
You can compare the result with the initial web page (see first image in the present article) and verify that QTP
Descriptive programming works correctly - it returns correct numbers of objects.
Summary:
• I've explained and shown the mechanism of QuickTest Professional Descriptive Programming (QTP DP).
• The present QTP tutorial explains how to get number of different objects - Edits, Links, Images, Buttons, etc.
I hope, that this article has helped you to understand QTP DP.
The future QTP tutorials will cover others questions on QTP Descriptive Programming.
Today I faced 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?
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:
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:
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:
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.
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"):
This is very useful feature - minimize QTP window before script execution. It allows to observe a desktop or an
application under test wholly.
I will show and describe how to minimize (or maximize) QTP window programmatically - i.e. from QTP script.
Also, provided approach can be applied to minimize (maximize) any required window - Browser, Notepad, MS Word
or Excel, and so on.
There are two ways to minimize QTP window:
1. Using Minimize method of Window object
2. Using QTP Application object - QuickTest.Application
These methods will contain several lines only and I hope that my explanations will be understandable.
So, let's explore!
1. Using Minimize method of Window object
<!--[if !supportLineBreakNewLine]-->You can use Minimize method of Window object to minimize QTP
window (or any other).
Let's see two cases - when a window is located in Object Repository (OR) and widows is not located in OR.
o If a window is located in Object Repository (OR), then minimizing can be performed using the
following code:
1. hWnd = Browser("browser_name").GetROProperty("hwnd")
2. Window("hwnd:=" & hWnd).Minimize
In first line, we get window handle (hWnd) of Browser object . And then we pass this handle to
Window object and minimize it.
Obviously, that we can use the same approach to maximize window (use method):
3. hWnd = Browser("browser_name").GetROProperty("hwnd")
4. Window("hwnd:=" & hWnd).Maximize
o If a window is not located in Object Repository (OR), then we can use some run-time object properties
and descriptive programming to identify a window. For example, we can use window title.
Well, you can use any approach you like. All of them work and minimize/maximize windows
correctly.
1.Sub MinimizeQTPWindow ()
2. Set qtApp = getObject("","QuickTest.Application")
3. qtApp.WindowState = "Minimized"
4. Set qtApp = Nothing
5.End Sub
6.MinimizeQTPWindow
For detailed information, I recommend to Read QTP Help > QuickTest Automation Object Model Reference.
Since QuickTest Automation Object Model does not use UI, second approach is more stable.
But first method is more flexible - it allows working with browsers and stand-alone windows.
In any case, I recommend to read and explore both approaches.
• Now - function returns the current date and time according to the setting of your computer's system date and
time.
• Date - function returns the current system date.
• Time - function returns a Variant of subtype Date indicating the current system time.
So, the code is very simple. I provide it with a screen shot containing results:
As you can see, initial date and time were '26.10.2007 22:45:10'. Then I added 3 days and 2 hours to initial date & time.
The result of addition is - '30.10.2007 0:45:10'.
By the way, could you guess, why the result day is 30th, not 29th? :) To answer, please pay attention that we added 2
hours too :)
The last step - running of time and date commands from command line. I used Run method of WScript.Shell object.
So, as you can see - date and time manipulation is easy enough.