Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1)Syntax:
system.util.run("path of the application")
this invokes any type of application.
2) 1).systemutil.run"path of the application"
.Invokeapplication"path of the application"
3) Systemutil.Run("iexplore")
Set vBrowser=Browser("Creationtime:=0")
vBrowser.navigate("Url of your application for example:
"gmail.com" ")
Description:
!)systemutil.run("URL")
or
systemutil.run "iexplore.exe","URL"
!!) systemutil.run("iexplore")
set vbrowser=createobject("creationtome:=0")
vbrowser.navigate"URL"
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:
I use
Object Repository (OR) to simplify my demo-scripts.
Since the browser & the page were added to OR, we can use them later like:
Browser("Google Labs").Page("Google Labs").
Child
Objects returns the collection of child objects matched the description ("micclass" is
"Link") and contained within the object (Page("Google Labs")).
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:
Note: you can download tidy.exe here for above QTP script.
Summary:
Related articles:
1. Fills 'Username' in
2. Fills 'Password' in
3. Clicks 'Sign in' button
By the way, there are two ways how to decrypt a password in QuickTest Professional:
1. Using Crypt.Encrypt
Summary:
There are two ways how to get all properties of an object in QuickTest Professional:
1. Manually
2. Programmatically
Please note that you can find the same Link Identification Properties in QuickTest
Professional Help:
QTP Object Identification Properties can be used:
For i = 0 to UBound(arrNames)
sNames = sNames & arrNames(i) & vbNewLine
Next
MsgBox sNames
The result is:
Next step is to read their values. It can be archived using GetTOProperty or GetROProperty.
Also, I'm going to show how GetTOProperty and GetROProperty work for Test Object
(located in QTP Object Repository) and Run-time Object (actual object, created during the run
session).
For i = 0 to UBound(arrNames)
sNamesTO = sNamesTO & arrNames(i) & ": " &
TestLink.GetTOProperty(arrNames(i)) & vbNewLine
sNamesRO = sNamesRO & arrNames(i) & ": " &
TestLink.GetROProperty(arrNames(i)) & vbNewLine
Next
MsgBox sNamesTO
MsgBox sNamesRO
o Test Object Properties of Test Object
Test Object Properties of Test Object and their values are:
For i = 0 to UBound(arrNames)
sNamesTO = sNamesTO & arrNames(i) & ": " &
TestLink.GetTOProperty(arrNames(i)) & vbNewLine
sNamesRO = sNamesRO & arrNames(i) & ": " &
TestLink.GetROProperty(arrNames(i)) & vbNewLine
Next
MsgBox sNamesTO
MsgBox sNamesRO
As I said, GetTOProperty function gets values from Test Object, which is stored
in QTP Object Repository. Since Run-time Object is a dynamic object, it's not
stored in QTP Object Repository. That's why GetTOProperty function cannot read
object's properties.
Look at the above screenshot again. The only one property ('text') contains its value
('Advanced Search'). We used this property to create description for our link:
In previous QTP tutorial I shown how QTP can read data from XML file.
Today I will explain how to update XML data from QTP.
Note: You
can download this XML file here.
Note: The numeration begins from zero. That's why I use book[0] to access first item.
Note: Use @
to access an attribute of XML node.
As you can
see, we've added "Mr. Noname" as the new author.
New
attribute of a boof and its value ("bestseller"="yes") have been added.
Well, the working with XML files from QTP is easy enough.
Summary:
The present QTP tutorial shows simple recipe how to rename Excel worksheet from QuickTest
Professional.
For example, Excel-file contains 'Sheet1' sheet:
Use the following QTP script, which perform the work using Excel's COM object -
"Excel.Application":
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
objWorksheet.Name = "VBScript_Excel"
objWorkbook.SaveAs ("c:\Book1.xls")
objExcel.Quit
Summary:
The present QTP video explains how to click dynamic links, which change their text.
For example, the number of email drafts can vary:
In previous QTP tutorial (QTP Descriptive Programming - How to get number of objects) I
explained how to get number of objects (Edits, Links, Buttons) with QTP Descriptive
Programming (QTP DP).
Today I'm going to show:
How to use QTP DP to perform different operations on objects.
For example, how to type text in these edit boxes on Google Sets page:
From previous QTP DP tutorial you know that this code returns a collection of Edits located on
Web page:
Set Desc = Description.Create()
Desc("micClass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)
So, to type text in each Edit, we have to process edit boxes from returned collection one by one.
We can access the specified item from a collection by item's index.
For example, the following code types a text in the first edit box:
Edits(0).Set("Text in Edit #1")
And its result is:
Note:
ChildObjects returns zero-based collection of found objects.
That's why use Edits(0) to access first item, Edits(1) to access second item, and so on.
NumberOfItems = Edits.Count
For i = 0 To NumberOfItems - 1
Edits(i).Set("Text in Edit #" & (i+1))
Next
This code fills all Edits in. So, the result page looks like:
As you
can see - QuickTest Professional Descriptive Programming works correctly.
Note: If the initial page contains more (i.e. 8) or less (i.e. 3) number of edit boxes, our QTP script
will work without changes!
Note: Since we do not use QTP Object Repository (QTP OR), this approach can be integrated
easily into any existing QTP system. Shared Object Repository is not required!
Summary:
The article shows how to perform operations on objects.
The approach uses QuickTest Professional Descriptive Programming.
I'm going to explain and show QTP Descriptive Programming (DP) through Google Sets site:
(click image to enlarge it)
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.
For example, the following global QTP Data Table contains 3 rows:
The iteration number of QTP test can be specified in 'File/Settings.../Test Settings dialog', 'Run'
tab:
If we run our QTP test with above settings (global DataTable & 'Run' tab), the test will pass 3
iteration.
So, the question is How to determine the current iteration number withing QTP script?
Answer: We can use the value of "TestIteration" environment variable -
Environment("TestIteration").
MsgBox str
And the result of above QTP script is:
When you work in QTP with Web applications, it is sometimes necessary to get a text of
browser's status bar.
Let's see for example the following browser:
To access text of Status Bar, we use Browser's Object object and its StatusText property.
Browser("bname").Object is a reference to the Internet Explorer's DOM object. To be more
precise, it's a reference to the Internet Explorer's IWebBrowser2 interface.
Using Browser("bname").Object, you can access different methods and properties of IE, for
example:
# Statement Meaning
1 Browser("bname").Object.GoBack Navigates backward one item in the history list
2 Browser("bname").Object.LocationURL Gets the URL of the page that is currently
displayed
3 Browser("bname").Object.StatusText Sets or gets the text in the status bar for the
object
4 Browser("bname").Object.ToolBar Sets or gets whether toolbars for the object are
visible
2.
So, our code is simpe enough:
3. sText = Browser("QTP - How to get Status").Object.StatusText
MsgBox sText
4. And its result is:
5.
6. Note: Since we use Internet Explorer's IWebBrowser2 interface, we can use this solution
win IE only. It doesn't work with FireFox. The next solution will be compatibe with both
IE and FF.
Status bar is a part of browser's window. There is a special class to handle it from QTP -
WinStatusBar. We can get text of WinStatusBar using GetROProperty("text") method.
Note: This solution works correctly both for IE and FF, but it requires additional operations
with Object Repository.
MsgBox "#2: " & Chr(34) & "QTP - QuickTest Professional" & Chr(34)
Since, the ANSI code if quotation mark = 34, we can use Chr function.
The result is:
QTP Descriptive Programming - How to close all Browsers?
This is a very practical task - How to close all browsers from QTP?
You may need to close browsers before or during the QTP script execution.
You can be surprised, but QTP script, that closes all browsers, will contain 3 lines only:
QTP Tip1: The first browser that opens receives the value "CreationTime" = 0, the second
browser receives "CreationTime" = 1, and so on...
QTP Tip2: To specify value of property in Descriptive Programming, please use ":=" operator.
For example, "Title:=My application".
Since we cannot know in advance - what browser will be selected and closed, we use its "age", i.e.
"CreationTime" property. We decide, which browser should be closed, during the QTP script
execution only.
For example, we have to close all browsers navigated to any Google's sites (URL contains
'google.com').
Using this QTP code, you can close dynamically browsers by mask.
Summary:
I've shown and explained:
I'm going to show and explain how to get current URL which is opened in a browser.
For example, how to get URL "http://motevich.blogspot.com" from the following browser:
Browser("bname").Page("pname").GetRoProperty("URL")
Browser("bname").Page("pname").Object.URL
Tip: You can use DOM Object when running QTP test on Internet Explorer only!
To make the long story short, I can say that using Object property you can get almost all
elements and properties from Web page.
Tip: The number of properties, accessed via DOM Object, is more bigger, than properties
accessed via GetROProperty method.
So, the result of above code is:
Summary:
Two ways were discussed:
GetROProperty method supports both IE & FireFox, but IE DOM Object provides more
accessible properties and methods.
Both can get URL of the current Web page.
In my previous post (QTP - How to capture tool tip?) I shown an example on capturing tool tip of
Web page link.
That solution uses FireEvent("onmouseover") and GetROProperty("text") to get tool tip of a
link.
Now, I'm going to show how to show how to capture tool tips of images located on a Web page.
Let's verify this code in practice. For example, let's check tooltips from Wikipedia Main page:
I've prepared QTP script, which gets all image from this page and checks their tooltips ("alt"
property):
Dim descImage, listImages, attrAltText, attrSrcText
When I run this code in QTP, it shows all images containing non-empty tool tip:
(click the image to enlarge it)
The same message boxes will be shown for others images on a Web page.
So, our solution is simple - use GetROProperty("alt") function to get tool tip of image.
As you can see - it works correctly.
Do you know how to do that? If not, do not sorrow :) I'm going to show and explain how to do
that.
Also, I'm going to explain QTP Descriptive Programming concepts.
Let's start with Google Book Search page:
Using "html tag" property and its value "IMG", we can create general description for all images
on the page. For that I use QTP Description object.
Description object is used to create a 'Properties' collection object. Each 'Property' object contains
a property name and value pair.
Set descImage = Description.Create
descImage("html tag").value = "IMG"
The above code:
You can use the following code to get number of all images on a Web page:
Dim descImage, listImages
In our example, we couldn't know all images on a Web page in advance. So, we couldn't add them
into QTP Object Repository. Instead of that, we created Description object with required property
and its value.
Tips: We can use several properties assigned to Description object. For example:
Set descImage = Description.Create
descImage("html tag").value = "IMG"
descImage("image type").value = "Image Link"
When we pass Description object to ChildObjects QTP function, it returns the collection of child
objects contained within the object (Page("Google Book Search")) and matched to Description
object.
That's why we've got the list of all images on a page.
There are "src" property, which contains the URL address of the image file.
To get this property, we can use GetROProperty QTP function.
Tips: Use the table of the most popular properties of Image QTP control:
# Property name Description
1 alt The object's tooltip text
2 href The location to which the browser navigates when the image is clicked
3 name The object's name
4 src The image source, i.e., the URL address of the image file
5 visible Indicates whether the object is visible.
Note: Only True and False are valid values for this property. 1 and 0 are not valid
values.
Please, refer Quicktest Professional Help for detailed info on image identification properties .
Tips: You can use the same approach to work with others UI controls - Links, WebEdit, WebList,
etc.
I will show how to perform automated testing of web applications on Internet Explorer (IE)
browser.
The main advantage is that these tests can be run on any Windows computer without any
additional sofware required.
I hope, the source code of my test is clean and understandable. Here it is:
Option Explicit
Dim objIE, objLink
Set objIE = OpenBrowser("http://google.com")
' View the HTML source on Google's page to see the 'q' and 'btnG'
values
objIE.Document.All("q").Value = "Easy way to automate testing"
objIE.Document.All("btnG").Click
WaitForLoad(objIE)
''''''''''''''''''''''''''''''''''''''''''''''
' Functions
ie.Visible = True
ie.Navigate2 URL
WaitForLoad(ie)
Set OpenBrowser = ie
End Function
Test
runs and performs all steps correctly (it opens IE, fills values, clicks button, clicks link, closes IE).
Conclusion:
You can create and use instances of the InternetExplorer object to perform and to test all actions,
which you run manually.
Or to do some routine operations in a browser, for example - filling forms, creating test users, and
so on.
I will show the way how to do that - i.e. how to run QTP tests from command line.
Using that approach, you can execute your QTP tests on the schedule.
This is a script, which runs QTP tests (from the above QTP video tutorial):
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object
This QTP video tutorial explains how to use QTP Text Output to capture dynamic text.
The present QTP (QuickTest Pro) video tutorial covers the following:
Dear Reader!
I'm a big fan of LoadRunner! Really. This is a wonderful tool for load and performance testing.
Also, I like QTP. Not love it, just like :) It's powerful enough.
That's why I decided to use them together - i.e. execute QTP script from LoadRunner.
I recorded simple QTP script - it just opens Google, performs search, then it clicks 'Next' button,
and closes browser:
It's OK :) I will share my experience and help you to answer these questions!
Let's sort them out one after another...
If you plan to execute QTP scripts, QTP should be installed on Load Generator computer
(or computers, if you to execute several concurrent QTP scripts).
I tried to execute QTP script on computer, where QTP was not installed, and I got this
error:
How does QTP work? It takes full control on GUI desktop of computer. Each computer has
one desktop only.
That's why there is a limitation: you can run one QTP script per computer!
Certainly, I tried to execute two QTP scripts on one Load Generator. One user passed
successfully and second generated the error:
But you can evade this restriction - use Terminal server or Citrix server. They allow to
create several virtual desktops. And you will be able to execute several QTP scripts on one
physical computer.
Since you have both QTP and LoadRunner licenses, it's expensive enough to run QTP
scripts from LoadRunner.
Note: Each QTP instance should have its license. If you use concurrent licenses and plan
execute 10 QTP scripts, then each QuickTest will require license - You should provide 10
seat or concurrent licenses.
I think, it is logical.
Note, that QTP scripts can be executed in LoadRunner Controller. You cannot use
LoadRunner Generator to run or debug QTP script.
That's funny,
LoadRunner set correct 'Quantity' value in Scenario Groups settings, but it forgot to
set correct values in Scenario Schedule section:
Execute scenario.
You will find that your QTP script works - it will be starting a browser,
performing search, clicking 'Next' btn and closing browser during 5 minutes
(default time from Global Schedule settings)
QTP allows running different types of test. And sometimes, it needs perform time and date
manipulations on a computer. In this article, I will show and explain - how to get system time/date
and change them.
• 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:
Now, I will combine all the above VBScript functions (Now, Date, Time) and DOC commands
(time and date):
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.
TP - How to get font size/color, background color and other attributes of controls
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:
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:
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:
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.
2. currentStyle object!
The main idea is to read:
WebElement("SomeName").Object.currentStyle.someProperty
For example, use:
o color property to get the color of the text
o backgroundColor property to get the backgroung color (behind the content of the
object)
o fontSize property to get the font size
o fontStyle property to get the font style
o fontFamily property to get the font family
o fontWeight property to get the font weight
o and so on
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:
Summary: The simple way to get different attributes of controls from QTP is a usage of
currentStyle object .