Friday, 19 August 2011

Checkpoints & Output Values


Check points overview

QuickTest enables you to add checks to your test. A checkpoint is a verification that compares the current value for specified properties or current state of other characteristics of an object with the expected value or characteristics. This helps you to identify whether your application is functioning correctly.

When you add a checkpoint, QuickTest inserts a checkpoint step to the current row in the Keyword View and adds a Check CheckPoint statement in the Expert View. By default, QuickTest names the checkpoint using the name of the test object on which the checkpoint was created. You can choose to specify a different name for the checkpoint or accept the default name.

When you run the test, QuickTest compares the expected results of the checkpoint to the current results. If the results do not match, the checkpoint fails. You can view the results of the checkpoint in the Run Results Viewer. 

Adding Existing Checkpoints to a Test
QuickTest enables you to reuse existing checkpoints. When you create checkpoints, consider which checkpoints can be reused in multiple locations in your test or in multiple tests. For example:
  • Checkpoints that check generic content or the state of your application may be useful in multiple locations.
  • Checkpoints that check the content of a specific area of your application are generally useful in only one particular place in your test.
The following examples illustrate situations in which inserting an existing checkpoint may be useful:
  • If each page of your application contains your organization's logo, you can reuse a bitmap checkpoint to verify each occurrence in the application.
  • If your application contains multiple edit boxes, you can reuse a checkpoint to confirm the enabled status of these edit boxes throughout your test.

Checkpoint Types

You can insert the following checkpoint types to check objects in an application:

Checkpoint Type
Description
Standard Checkpoint
Checks property values of an object in your application. For example, you can check that a radio button is activated after it is selected or you can check the value of an edit box.
Standard checkpoints are supported for all add-in environments.
Image Checkpoint
Checks the value of an image in your application. For example, you can check that a selected image's source file is correct.
You create an image checkpoint by inserting a standard checkpoint on an image object.
Image checkpoints are supported for the Web add-in environment.
Bitmap Checkpoint
Checks an area of your application as a bitmap. For example, suppose you have a Web site that can display a map of a city the user specifies. The map has control keys for zooming. Using the bitmap checkpoint, you can check that the map zooms in correctly.
You can create a bitmap checkpoint for any area in your application.
Bitmap checkpoints are supported for all add-in environments.
Table Checkpoint
Checks information within a table. For example, suppose your application contains a table listing all available flights from New York to San Francisco. You can add a table checkpoint to check that the time of the first flight in the table is correct.
You create a table checkpoint by inserting a standard checkpoint on a table object.
Table checkpoints are supported for all add-in environments that have a *Table test object. Table checkpoints are also supported for some list view objects, such as WinListView and VbListView, as well as other list view objects in add-in environments.
Text Checkpoint
Checks that a text string is displayed in the appropriate place in an application. For example, suppose a Web page displays the sentence Flight departing from New York to San Francisco. You can create a text checkpoint that checks that the words "New York" are displayed between "Flight departing from" and "to San Francisco".
Text checkpoints are supported for most add-in environments.
Text Area Checkpoint
Checks that a text string is displayed within a defined area in a Windows-based application, according to specified criteria. For example, suppose your Visual Basic application has a button that says View Doc <Num>, where <Num> is replaced by the four digit code entered in a form elsewhere in the application. You can create a text area checkpoint to confirm that the number displayed on the button is the same as the number entered in the form.
Text area checkpoints are supported for all Windows-based environments, such as Standard Windows, Visual Basic, and ActiveX add-in environments. Text area checkpoints are also supported for some other add-in environments, such as Java.
Accessibility Checkpoint
Identifies areas of your Web site that may not conform to the World Wide Web Consortium (W3C) Web Content Accessibility Guidelines. For example, guideline 1.1 of the W3C Web Content Accessibility Guidelines requires you to provide a text equivalent for every non-text element. You can add an Alt property check to check whether objects that require the Alt property under this guideline, do in fact have this tag.
Accessibility checkpoints are supported for the Web add-in environment.
Page Checkpoint
Checks the characteristics of a Web page. For example, you can check how long a Web page takes to load or whether a Web page contains broken links.
You create a page checkpoint by inserting a standard checkpoint on a page object.
Page checkpoints are supported for the Web add-in environment.
Database Checkpoint
Checks the contents of a database accessed by your application. For example, you can use a database checkpoint to check the contents of a database containing flight information for your Web site.
Database checkpoints are supported for all add-in environments.
XML Checkpoint
Checks the data content of XML documents in XML files or XML documents in Web pages and frames.
The XML Checkpoint (Web Page/Frame) option is supported for the Web add-in environment. The XML Checkpoint option is supported for all add-in environments.


Output Values Overview

QuickTest enables you to retrieve values in your test and store them in output value objects. You can subsequently retrieve these values and use them as input at a different stage in the run session.
An output value step is a step in which one or more values are captured at a specific point in your test and stored for the duration of the run session. The values can later be used as input at a different point in the run session.
You can output the property values of any object. You can also output values from text strings, table cells, databases, and XML documents.
When you create output value steps, you can determine where the values are stored during the run session and how they can be used. During the run session, QuickTest retrieves each value at the specified point and stores it in the specified location. When the value is needed later in the run session, QuickTest retrieves it from this location and uses it as required.
Output values are stored only for the duration of the run session. When the run session is repeated, the output values are reset.
Note: After the run session, you can view the output values retrieved during the session as part of the session results.

Output Value Categories

You can create the following categories of output values: 

Standard Output Values
You can use standard output values to output the property values of most objects. For example, in a Web-based application, the number of links on a Web page may vary based on the selections a user makes on a form on the previous page. You could create an output value in your test to store the number of links on the page.
Note:
·  You can also use standard output values to output the contents of table cells.
·  You can use standard output values to output text strings by specifying the text property of the object as an output value. 

Table Output Values
Table output values are a subset of standard output values. You can use table output values to output the contents of table cells. For some types of tables, you can specify a row range from which to choose the table cells. During the run session, QuickTest retrieves the current data from the specified table cells according to the settings that you specified and outputs the values to the data table. 

Text and Text Area Output Values
You can use text output values to output text strings displayed in an application. When creating a text output value, you can output a part of the object's text. You can also specify the text before and after the output text.
You can use text area output values to output text strings displayed within a defined area of a screen in a Windows-based application.
For example, suppose that you want to store the text of any error message that appears after a specific step in the Web application you are testing. Inside the If statement, you check whether a window exists with a known title bar value, for example Error. If it exists, you output the text in this window (assuming that the window size is the same for all possible error messages).
Note: You can create a text area output value only while recording on Windows-based applications. 

Database Output Values
You can use database output values to output the value of the contents of database cells, based on the results of a query (result set) that you define on a database. You can create output values from the entire contents of the result set, or from a part of it. During the run session, QuickTest retrieves the current data from the database and outputs the values according to the settings that you specified. 

XML Output Values
You can use XML output values to capture and output the values of XML elements and attributes in XML documents.
For example, suppose that an XML document in a Web page contains a price list for new cars. You can output the price of a particular car by selecting the appropriate XML element value to output.
After the run session has finished, you can also view the captured data by opening the XML Output Value Results window from the Run Results Viewer. 

Existing Output Values
QuickTest enables you to insert existing output values into your test.
When you insert an existing output value in your test, consider which output values should be used in multiple locations in your test. Each time an output value step is performed, the value contained in the output value is overwritten with the new output value. You should insert an existing output value into your test only if the stored value will no longer be needed by your test when the output value object is used again.

Thursday, 18 August 2011

Descriptive Programming

Advantages of Descriptive Programming
a) Descriptive Programming based Test scripts are faster in execution than Repository based Test scripts.
b) Scripts are portable (we can run these scripts from any machine easily)
c) Maintenance is easy (less amount of resources)
d) We can start Test Execution process even though Application is not ready.

Programmatic Descriptions

When QuickTest learns an object in your application, it adds the appropriate test object to the object repository. After the object exists in the object repository, you can add statements in the Expert View to perform additional operations on that object. To add these statements, you usually enter the name (not case sensitive) of each of the objects in the object's hierarchy as the object description, and then add the appropriate operation.
Because each object in the object repository has a unique name, the object name is all you need to specify. During the run session, QuickTest finds the object in the object repository based on its name and parent objects, and uses the stored test object description for that test object to identify the object in your application.
You can also instruct QuickTest to perform operations on objects without referring to the object repository or to the object's name. To do this, you provide QuickTest with a list of properties and values that QuickTest can use to identify the object or objects on which you want to perform an operation.
Such a programmatic description can be very useful if you want to perform an operation on an object that is not stored in the object repository. You can also use programmatic descriptions to perform the same operation on several objects with certain identical properties, or to perform an operation on an object whose properties match a description that you determine dynamically during the run session.
In the Run Results, square brackets around a test object name indicate that the test object was created dynamically during the run session using a programmatic description or the ChildObjects method.

Use case scenario:
Suppose you are testing a Web site that generates a list of potential employers based on biographical information you provide, and offers to send your resume to the employer names you select from the list. You want your test to select all the employers displayed in the list, but when you design your test, you do not know how many check boxes will be displayed on the page, and you cannot, of course, know the exact object description of each check box. In this situation, you can use a programmatic description to instruct QuickTest to perform a Set "ON" method for all objects that fit the description: HTML TAG = input, TYPE = check box.
Programmatic Description Types
There are two types of programmatic descriptions:
  • Static. You list the set of properties and values that describe the object directly in a VBScript statement.
  • Dynamic. You add a collection of properties and values to a Description object, and then enter the Description object name in the statement.
Using the Static type to enter programmatic descriptions directly into your statements may be easier for basic object description needs. However, in most cases, using the Dynamic type provides more power, efficiency, and flexibility.

Static Programming

Static Programmatic Descriptions

You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object's name.
The general syntax is:
TestObject("PropertyName1:=PropertyValue1", "..." , "PropertyNameX:=PropertyValueX")
TestObject. The test object class.
PropertyName:=PropertyValue. The identification property and its value. Each property:=value pair should be separated by commas and quotation marks.
The statement below specifies a WebEdit test object in the Mercury Tours page with the Name author and an index of 3. During the run session, QuickTest finds the WebEdit object with matching property values and enters the text Mark Twain.
Browser("Mercury Tours").Page("Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"
Guidelines for Using Static Programmatic Descriptions
When working with static programmatic descriptions, be aware of the following guidelines:
Regular Expressions in Programmatic Descriptions
QuickTest evaluates all property values in programmatic descriptions as regular expressions. Therefore, if you want to enter a value that contains a special regular expression character (such as *, ?, or +), use the \ (backslash) character to instruct QuickTest to treat the special characters as literal characters.
Variables in Programmatic Descriptions
You can enter a variable name as the property value if you want to find an object based on property values you retrieve during a run session. For example:
MyVar="some text string"
Browser("Hello").Page("Hello").Webtable("table").Webedit("name:=" & MyVar)
Programmatic Descriptions for Parent Test Objects
When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onward within the same statement. If you specify a test object by its object repository name after parent objects in the hierarchy have been specified using programmatic descriptions, QuickTest cannot identify the object.

Example
  • You can use the following statement, which uses object repository names for the parent objects and a programmatic description for the object on which the operation is performed:
Browser("Mercury Tours").Page("Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"
  • You can use the following statement since it uses programmatic descriptions throughout the entire test object hierarchy:
Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"
  • You can also use the statement below, since it uses programmatic descriptions from a certain point in the description (starting from the Page object description):
Browser("Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"
  • However, you cannot use the following statement, since it uses programmatic descriptions for the Browser and Page objects but then attempts to use an object repository name for the WebEdit test object:
Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Author").Set "Mark Twain"
In this case, QuickTest tries to locate the WebEdit object based on its name, but cannot locate it in the repository because the parent objects were specified using programmatic descriptions.
Reuse of Static Programmatic Descriptions
If you want to use the same static programmatic description several times in one test or in one function library, you may want to assign the object you create to a variable or use a With statement.

Example
Instead of entering:
Window("Text:=Myfile.txt - Notepad").Move 50, 50
Window("Text:=Myfile.txt - Notepad").WinEdit("AttachedText:=Find what:").Set "hello"

Window("Text:=Myfile.txt - Notepad").WinButton("Caption:=Find next").Click
You can enter:
Set MyWin = Window("Text:=Myfile.txt - Notepad")
MyWin.Move 50, 50

MyWin.WinEdit("AttachedText:=Find what:").Set "hello"

MyWin.WinButton("Caption:=Find next").Click
Alternatively, you can use a With statement:
With Window("Text:=Myfile.txt - Notepad")     .Move 50, 50     .WinEdit("AttachedText:=Find what:").Set "hello"     .WinButton("Caption:=Find next").Click
End With
For more information on the With statement, see With Statement.
Copying Programmatic Description Data from the Object Spy
You can use the Copy Identification Properties to Clipboard option in the Object Spy dialog box to copy all identification properties and values for a selected object to the Windows Clipboard. The copied values are formatted in standard programmatic description syntax with line breaks between each property-value pair. For example:
"Class Name:=Image",
"abs_x:=585",
"abs_y:=573",
"alt:=Specials",
....
You can paste the copied data to any document and then copy selected lines (remove the line breaks) into a programmatic description.

Dynamic Programming

Dynamic Programmatic Descriptions

You can use the Description object to return a Properties collection object containing a set of Property objects. A Property object consists of a property name and value. You can then specify the returned Properties collection in place of an object name in a statement. (Each property object contains a property name and value pair.)
To create the Properties collection, you enter a Description.Create statement using the following syntax:
Set MyDescription = Description.Create()
After you have created a Properties object (such as MyDescription in the example above), you can enter statements to add, edit, remove, and retrieve properties and values to or from the Properties object during the run session. This enables you to determine which, and how many properties to include in the object description in a dynamic way during the run session.
After you fill the Properties collection with a set of Property objects (properties and values), you can specify the Properties object in place of an object name in a test statement.
For example, instead of entering:
Window("Error").WinButton("text:=OK", "width:=50").Click
you can enter:
Set MyDescription = Description.Create()
MyDescription("text").Value = "OK"
MyDescription("width").Value = 50
Window("Error").WinButton(MyDescription).Click
            
When working with Properties objects, you can use variable names for the properties or values to generate the object description based on properties and values you retrieve during a run session.
You can create several Properties objects in your test if you want to use programmatic descriptions for several objects.

Notes for Description objects
  • By default, the value of all Property objects added to a Properties collection are treated as regular expressions. Therefore, if you want to enter a value that contains a special regular expression character (such as *, ?, +), use the \ (backslash) character to instruct QuickTest to treat the special characters as literal characters.
  • You can set the RegularExpression property to False to specify a value as a literal value for a specific Property object in the collection. For more information, see the Utility section of the HP QuickTest Professional Object Model Reference.
  • When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have been described using programmatic descriptions, QuickTest cannot identify the object.
For example, you can use Browser(Desc1).Page(Desc1).Link(desc3), since it uses programmatic descriptions throughout the entire test object hierarchy.
You can also use Browser("Index").Page(Desc1).Link(desc3), since it uses programmatic descriptions from a certain point in the description (starting from the Page object description).
However, you cannot use Browser(Desc1).Page(Desc1).Link("Example1"), since it uses programmatic descriptions for the Browser and Page objects but then attempts to use an object repository name for the Link test object (QuickTest tries to locate the Link object based on its name, but cannot locate it in the repository because the parent objects were specified using programmatic descriptions).

Creating Library files using Constants /Collection objects
If we want maintain ‘Objects information’ in centralized location then we can use Constants.
Steps:

Creating Constants:
Const Login=”text:=Login”, Agent=”attached text:=Agent Name:”
Const Pwd =”attached text:=Password:”, Ok=”text:=OK”
Note: we can declare no of Constants in a line by separating with Camas (,), if we take other line then we have to use Const Statement again.

Creating a Library file
Place Constants in Notepad and save as .vbs file
Associate the Library file to QTP (File->Settings->Resources-> Click add (+) icon-> Browse path of the Library file->Click Apply and click Ok buttons
Otherwise, we can load the library file during run-time
Syntax:
ExecuteFile “Path of the Library file(.vbs)”
After that create the Test Script using Constants

Creating the Test Script using Constants:
Invokeapplication “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(Login).Activate
Dialog(Login).Winedit(Agent).Set “asdf”
Dialog(Login).Winedit(Pwd”).Set “mercury”
Dialog(Login).Winbutton(Ok).Click
Advantages:
If we maintain Object Information in the centralized location, then we can handle modifications easily.
——————————————————————-
Dynamic Programming

In this style of script generation, first we create description objects, provide properties information and use description objects in the test script.

Creating Properties Collection Objects

Set oLogin=description.Create

Set oAgent=description.Create

Set oPassword=description.Create

Set oOk=description.Create

Entering Properties Information into Objects

oLogin(“text”).value=”Login”

oLogin(“width”).value=320

oLogin(“height”).value=204

oAgent(“attached text”).value=”Agent Name:”

oPassword(“attached text”).value=”Password:”

oOk(“text”).value=”OK”

Generating Tests using Properties collection Objects

Invokeapplication “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”

Dialog(oLogin).Activate

Dialog(oLogin).Winedit(oAgent).Set “asdf”

Dialog(oLogin).Winedit(oPassword).Set “mercury”

Dialog(oLogin).Winbutton(oOK).Click

Note1: Create Description objects and put into one library file, by associating that library file, we can generate tests.

Note2: Dynamic programming is some difficult in preparation than static programming but maintenance is very easy.

—————————————————-

In this style of script creation also, we can maintain Objects information in the Centralized location by putting collection objects in a Library file.

Retrieving Child Objects

Retrieving Child Objects

You can use the ChildObjects method to retrieve  all objects located inside a specified parent object, or only those child objects that fit a certain programmatic description. To retrieve this subset of child objects, you first create a description object and add the set of properties and values that you want your child object collection to match using the Description object.
Note: You must use the Description object to create the programmatic description for the ChildObjects description argument. You cannot enter the programmatic description directly into the argument using the property:=value syntax.
After you have built a description in your description object, use the following syntax to retrieve child objects that match the description:
Set MySubSet=TestObject.ChildObjects(MyDescription)

Example
The statements below instruct QuickTest to select all of the check boxes on the Itinerary Web page:
Set MyDescription = Description.Create()
MyDescription("html tag").Value = "INPUT"
MyDescription("type").Value = "checkbox"
Set Checkboxes = Browser("Itinerary").Page("Itinerary").ChildObjects(MyDescription)
NoOfChildObjs = Checkboxes.Count
For Counter=0 to NoOfChildObjs-1
    Checkboxes(Counter).Set "ON"
Next
In the Run Results, square brackets around a test object name indicate that the test object was created dynamically during the run session using the ChildObjects method or a programmatic description.

Using the Index Property in Programmatic Descriptions
The index property can sometimes be a useful identification property for uniquely identifying an object. The index identification property identifies an object based on the order in which it appears within the source code, where the first occurrence is 0.
Index property values are object-specific. Thus, if you use an index value of 3 to describe a WebEdit test object, QuickTest searches for the fourth WebEdit object in the page.
If you use an index value of 3 to describe a WebElement object, however, QuickTest searches for the fourth Web object on the page regardless of the type, because the WebElement object applies to all Web objects.
For example, suppose you have a page with the following objects:
  • An image with the name Apple
  • An image with the name UserName
  • A WebEdit object with the name UserName
  • An image with the name Password
  • A WebEdit object with the name Password
The description below refers to the third item in the list above, as it is the first WebEdit object on the page with the name UserName:
WebEdit("Name:=UserName", "Index:=0")
The following description, however, refers to the second item in the list above, as that is the first object of any type (WebElement) with the name UserName:
WebElement("Name:=UserName", "Index:=0")
Note: If there is only one object, using index=0 will not retrieve it. You should not include the index property in the object description.

Methods/Operations
Activate Method

1)
Description
Activates (double-clicks) the specified item in the list.

Syntax
object.Activate Item, [BUTTON]

Syntax Details

Argument
Description
object
A test object of type WinList.
Item
Required. A Variant value. The item to select from the list. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
BUTTON
Optional. A predefined constant or number. See the Constants table, below. The mouse button used to activate the list item. Default = micLeftBtn (0). 


The possible values for the BUTTON argument are:

Constant
Value
Description
micLeftBtn
0
The left mouse button. 
micRightBtn
1
The right mouse button. 
micMiddleBtn
2
The middle mouse button. 


Return Type
None 


Example
Double-Click an Item in a List by Name or Index
Sub Activate_Example()
'The following example uses the Activate method to double-click the
'MyFile item in the Files list.

Dialog("Open").WinList("Files").Activate "MyFile"

'or

Dialog("Open").WinList("Files").Activate 2

End Sub



2)
Description
Activates the window.

Syntax
object.Activate [BUTTON]

Syntax Details

Argument
Description
object
A test object of type Window.
BUTTON
Optional. A predefined constant or number. See the Constants table, below. The mouse button used to click the window. Default = micLeftBtn (0). 


The possible values for the BUTTON argument are:

Constant
Value
Description
micLeftBtn
0
The left mouse button. 
micRightBtn
1
The right mouse button. 
micMiddleBtn
2
The middle mouse button. 


Return Type
None 

Example
Activate a Window
Sub Activate_Example()
'The following example uses the Activate method to activate the
'Notepad window.

Window("Notepad").Activate

End Sub



Click Method
Description
Clicks the object.

Important Information
Recording options for this method are defined in the Advanced tab of the Web Options dialog box.

For some FireFox objects, this method is recorded only if handler is present. For details, see Working with Web Browsers in the QuickTest Professional Web Add-in Guide.

Syntax
object.Click [x], [y], [BUTTON]

Syntax Details

Argument
Description
object
A test object of type WebButton.
x
Optional. A Long value.
The x-coordinate of the click. The specified coordinates are relative to the upper left corner of the object. Default = micNoCoordinate (-9999) -- center of the object.
y
Optional. A Long value.
The y-coordinate of the click. The specified coordinates are relative to the upper left corner of the object. Default = micNoCoordinate (-9999) -- center of the object.


Tip: You can enter micNoCoordinate (-9999) for the X and Y argument values if you want to enter a value for the button argument without specifying x- and y- coordinates for the click. micNoCoordinate indicates the center of the object.
BUTTON
Optional. A predefined constant or number. See the Constants table, below.
The mouse button used to click the object. Default = micLeftBtn (0). QuickTest does not record the Click method for right- or middle-clicks. Instead, QuickTest records the RightClick and MiddleClick methods



The possible values for the BUTTON argument are:

Constant
Value
Description
micLeftBtn
0
The left mouse button. 
micRightBtn
1
The right mouse button. 
micMiddleBtn
2
The middle mouse button. 


Return Type
None 

Example
Click a Button 
Sub Click_Example()
'The following example uses the Click method on the Submit button.

Browser("QA Home Page").Page("QA Home Page").WebButton("Submit").Click

End Sub


Click the WebElement with HTML TAG=Form
Sub Click_Example()
'The following example uses the Click method on a form.

Browser("New Page").Page("New Page").WebElement("html tag:=Form").Click

End Sub


Close Method

1)

Closes an open TextStream file.

Syntax
object.Close( );

Example
Sub CreateAFile
   Dim fso, MyFile
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
   MyFile.WriteLine("This is a test.")
   MyFile.Close
End Sub


2)
Closes the browser window (or tab) that this test object represents.

Important Information
Use the CloseAllTabs method to close the currently open tab, all sibling tabs, and the parent browser window.

Syntax
object.Close

Syntax Details

Argument
Description
object
A test object of type Browser.


Return Type
None 

Example
Close the Browser
Sub Close_Example()
'The following example uses the Close method to close the
'Mercury Tours application.

Browser("Mercury Tours").Page("Search Results").Image("reserveFlights").Click 41, 20
Browser("Mercury Tours").Page("Method of Payment").Image("buyFlights").Click 11, 5
Browser("Mercury Tours").Close

End Sub


3)

Closes the window.

Syntax
object.Close

Syntax Details

Argument
Description
object
A test object of type Window.


Return Type
None 

Example
Close a Window
Sub Close_Example()
'The following example uses the Close method to close the Notepad window.

Window("Notepad").Close

End Sub

CloseAllTabs Method

Description
Closes all tabs (if any) and closes the browser window.

Important Information
This method closes all of the following:

  • the tab that is currently open
  • all sibling tabs in the parent browser window
  • the parent browser window
Note: Use the Close method to close only the tab (and the browser if the browser contains one or no tabs).

Syntax
object.CloseAllTabs

Syntax Details

Argument
Description
object
A test object of type Browser.


Return Type
None 

Example
Close All Tabs in the Browser
Sub CloseAllTabs_Example()
'The following example uses the CloseAllTabs method to close all the tabs
'in a Web browser.
Browser("Mercury Tours").Page("Search Results").Image("reserveFlights").Click 41, 20
Browser("Mercury Tours").Page("Method of Payment").Image("buyFlights").Click 11, 5
'Open another tab in the browser
Browser("Mercury Tours").OpenNewTab
'Perform an operation on the second tab
Browser("Google Browser").Page("Google").WebEdit("q").Set "Hello World"
'Close both tabs
Browser("Mercury Tours").CloseAllTabs
'or you can use the following line as well
'Browser("Google Browser").CloseAllTabs
End Sub


DblClick Method

Description
Double-clicks an object.

Syntax
object.DblClick X, Y, [BUTTON]

Syntax Details

Argument
Description
object
A test object of type WinButton.
X
Required. An Integer value.
The x-coordinate of the double-click. Note that the specified coordinates are relative to the upper left corner of the object.
Y
Required. An Integer value.
The y-coordinate of the double-click. Note that the specified coordinates are relative to the upper left corner of the object.
BUTTON
Optional. A predefined constant or number. See the Constants table, below.
The mouse button used to double-click the object. Default = micLeftBtn (0).



The possible values for the BUTTON argument are:

Constant
Value
Description
micLeftBtn
0
The left mouse button. 
micRightBtn
1
The right mouse button. 
micMiddleBtn
2
The middle mouse button. 
  

Return Type
None 

Example
Perform a Right Double-click on a WinListView Control
Sub DblClick_Example()
'The following example uses the DblClick method to double-click a right
'mouse button at coordinates 73, 120 on the SysListView32 object.

Window("Exploring").WinListView("SysListView32").DblClick 73, 120, 1

End Sub


Set Method

Description
Sets the value in the edit box.

Important Information
During a recording session, QuickTest inserts a single Set step regardless of how you select a file. This means that if you select a file by browsing to it and choosing it in a dialog box, or if you enter its path manually in an edit box, QuickTest inserts a single Set step.
Syntax
object.Set Text

Syntax Details

Argument
Description
object
A test object of type WebFile.
Text
Required. A String value. The new value of the object.


Return Type
None 


Examples
Enter a Path in a Browse Box
Sub Set_Example()
'The following example uses the Set method to insert the desired text in the name-of-files WebFile object.
Browser("Fill-Out-Form").Page("Fill-Out-Form").WebFile("name-of-files").Set "c:\tmp\txt.log"

'Here is another example
Browser("Fill-Out Form Example").Page("Fill-Out Form Example").WebFile("name_of_files").Set "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

End Sub

Enter a Value in an Edit Box 
Sub Set_Example()
'The following example uses the Set method to insert the desired
'number of passengers in the Number of Passengers edit box.

Browser("Mercury Tours").Page("Find Flights").WebEdit("numPassengers").Set "4"

End Sub



SetSecure Method

Description
Sets the encrypted value of an edit box.


Important Information
The SetSecure method is recorded when a password or other secure text is entered. The text is encrypted while recording, and decrypted during the test run.
To find the encrypted value to use as the argument for the SetSecure method, use the Password Encoder utility (Start > Programs > HP QuickTest Professional > Tools > Password Encoder) or parameterize the argument using a Data Table parameter and use the Data Table encryption option (right-click each unencrypted value in the password column and choose Data > Encrypt).

While the SetSecure method enables you to hide passwords on the screen during a run session, it is not intended to be a secure way to protect password information.

Syntax
object.SetSecure EncryptedText

Syntax Details

Argument
Description
object
A test object of type WebEdit.
EncryptedText
Required. A String value. The encrypted text to be entered in the edit field. 


Return Type
None 


Examples
Enter an Encrypted Value in an Edit Box 
Sub SetSecure_Example()
'The following example uses the SetSecure method to set an edit
'boxes value in encrypted form.
Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").Set "mercury"
Browser("Mercury Tours").Page("Mercury Tours").WebEdit("password").SetSecure "38cf389da9621eb4822cd7"

End Sub



Enter an Encrypted Password in an Edit Box
Sub Set_SetSecure_Submit_Example()
'The following example enters a user name in an edit box.
'Then it enters a secure password. Finally, it submits the form.

Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "mercury"
'You can generate an encoded string for the password using the QuickTest Password Encoder tool.
'To open the tool, choose Start > Programs > QuickTest Professional > Tools > Password Encoder.
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "45850fbdaec056421d43bd566351a25d8b9b3ccf"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Submit

End Sub


Select Method

Description
Selects the specified radio button from the radio group, replacing the previous selection.

Syntax
object.Select Value

Syntax Details

Argument
Description
object
A test object of type WebRadioGroup.
Value
Required. A String value. The value to select. The value can either be one of the items in the list or an index. To specify the index of the item to select, use "#index". Index values begin with 0.


Return Type
None


Examples
Select a Radio Button Option (1) 
Sub Select_Example1()
'The following example uses the Select method to select the Window
'item in a Web radio group in the seating preference section of
'the Mercury Tours application.

Browser("Mercury Tours").Page("Find Flights").WebRadioGroup("seat pref").Select "Window"

End Sub


Select a Radio Button Option (2)
Sub Select_Example2()
'The following example uses the Select method to check if a radio group
'has the value of "Two", and, if not, selects the "Two" radio button.

CurrentValue = Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").GetTOProperty("value")

If CurrentValue <> "Two" Then
Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").Select "Two"
End If

End Sub

GetVisibleText Method

Description
Returns the text from the specified area.

Important Information
The text to capture must be visible in the application window when the step runs.
The area is defined by pairs of coordinates that designate two diagonally opposite corners of a rectangle.
The results of this method may be different depending on the settings selected in the Text Recognition pane of the Options dialog box (Tools menu > Options item > General node > Text Recognition node).
The results of this method may be different in different run sessions depending on the operating system version you are using, service packs you have installed, other installed toolkits, the APIs used in your application, and so on.  Therefore, when possible, it is highly recommended to use the GetROProperty method to retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetVisibleText method.

Syntax
object.GetVisibleText ([Left], [Top], [Right], [Bottom])

Syntax Details

Argument
Description
object
A test object of type WinRadioButton
Left
Optional. A Long value.
The left coordinate of the search area within the object’s window.
Top
Optional. A Long value.
The top coordinate of the search area the object’s window.
Right
Optional. A Long value.
The right coordinate of the search area within the object’s window.
Bottom
Optional. A Long value.
The bottom coordinate of the search area a within the object’s window.


Note: If the Left, Top, Right, and Bottom arguments are not specified, the method returns all of the text within the visible part of the specified object.


Return Type
A String value. 

Examples
Type a Login Name if Specified Text Appears in a Window
Sub GetVisibleText_Example1()
'The following example uses the GetVisibleText method to retrieve the
'text from the Telnet window. If the returned string contains the "login:"
'sub-string, the Type method is used to type the guest string in the
'window.

TelnetText = Window("Telnet").GetVisibleText
If InStr(1, TelnetText, "login:", 1) > 0 Then
  Window("Telnet").Type "guest"
End If

End Sub



Return a Failed Message to the Report if Certain Text Appears in an Object
Sub GetVisibleText_Example2()
'The following example uses the GetVisibleText method to retrieve
'the text within the specified coordinates. If the returned string is
'not Catalog, the ReportEvent method is used to report a failed step.

theText = Window("Traders").WinObject("UserControl").GetVisibleText(16, 25, 56, 92)
If theText <> "Catalog" Then
 Reporter.ReportEvent micFail, "Traders", "Text check failed"
End If

End Sub


GetROProperty Method

Description
Returns the current value of the specified identification property from the object in the application.


Syntax
object.GetROProperty (Property, [PropertyData])


Syntax Details

Argument
Description
object
A test object of type WebButton.
Property
Required. A String value.
The property to retrieve from the object.
PropertyData
Optional. A Variant value.
Not in use.


Return Type
A Variant value. 


Examples
Retrieve the Current State of a Check Box 
Sub GetROProperty_Example()
'The following example uses the GetROProperty method to retrieve
'the state of a check box.

Val = Browser("Mercury Tours").Page("Find Flights").WebCheckBox("roundtrip").GetROProperty("Value")
' val contains the ON or OFF state of the check box

End Sub




Retrieve the Value of a Property in an Edit Box 
Sub GetROProperty_Example()

'The following example iterates through the WebEdit objects
'on a page, searching for a specific WebEdit object in order
'to set a value for it.

Dim EditToSearch, ValueToSet, NumberOfEdits

'This is the value of the 'name' property for the WebEdit we want to find.
EditToSearch = "credit_card_number"

ValueToSet = "6543210123456789"
'Create a description object to help retrieve all WebEdit objects in a specific page.
Set oDesc = Description.Create()
oDesc("micclass").Value = "WebEdit"
'Retrieve all WebEdit objects in this page
Set EditCollection = Browser("Book a Flight: Mercury").Page("Book a Flight: Mercury").ChildObjects(oDesc)

NumberOfEdits = EditCollection.Count
'Search for a specific WebEdit and set its value
For i = 0 To NumberOfEdits - 1
    If EditCollection(i).GetROProperty("name") = EditToSearch Then
        EditCollection(i).Set ValueToSet
    End If
Next
End Sub




Retrieve the Number of Radio Buttons in a Radio Group
Sub GetROProperty_Example()
'The following example uses the GetROProperty method to retrieve
'the number of items in a WebRadioGroup.

NumOfItems = Browser("Mercury Tours").Page("Find Flights").WebRadioGroup("seat pref").GetROProperty("Items Count")
' NumOfItems contains "3"

End Sub





GetContent Method

Description
Returns a string containing the names of all of the items in the combo box.

Syntax
object.GetContent

Syntax Details

Argument
Description
object
A test object of type WinComboBox.

Return Type
A String value.  The returned string contains all of the items in the list separated by VBScript line feed characters.

Example
Retrieve a List of Items in a Combo Box
Sub GetContent_Example()
'The following example uses the GetContent method to return the
'items in the Fly From list.

With Window("Flight Reservation")
     content = .WinComboBox("Fly From:").GetContent
End With

End Sub


GetItemsCount Method

Description
Returns the number of tabs in the tab strip.

Syntax
object.GetItemsCount

Syntax Details

Argument
Description
object
A test object of type WinTab.


Return Type
A Long value. 

Example
Find the Number of Tabs in a Tab Strip
Sub GetItemsCount_Example()
'The following example uses the GetItemsCount method to return the
'number of tabs in the SysTabControl32 object.

With Window("WinBurger")
    With .Dialog("Food Inventory")
        cnt = .WinTab("SysTabControl32").GetItemsCount
    End With
End With

End Sub



GetItem Method

Description
Returns the value of the item specified by the index.

Syntax
object.GetItem (Item)

Syntax Details

Argument
Description
object
A test object of type WinList.
Item
Required. A Variant value. Numeric index of the item. Index values begin with 0.




Return Type
A String value. 

Example
Retrieve the Value of an Item in a List
Sub GetItem_Example()
'The following example uses the GetItem method to return the value of
'the second item in the list.

itemVal = Window("WinBurger").WinList("ListBox").GetItem(1)

End Sub


Sync Method

Description
Waits for the browser to complete the current navigation.

Important Information
For FireFox, this method is recorded as a Page method.

Syntax
object.Sync

Syntax Details
Argument
Description
object
A test object of type Browser.


Return Type
None

Example
Synchronize the Navigation to a Web Page
Sub Sync_Example()
'The following example uses the Sync method to complete the navigation to the specified page.

SystemUtil.Run "iexplore.exe", "http://www.google.com"
Browser("Google").Page("Google").Sync
Browser("Google").Navigate "http://www.cnn.com"
Browser("Google").Page("CNN.com - Breaking News,").Sync
Wait 10 ' we can read the latest news
Browser("Google").Back

End Sub

Navigate Method


Description
Opens a specified URL in the browser.

Syntax
object.Navigate Location, [TargetFrame], [PostData], [Headers]

Syntax Details

Argument
Description
object
A test object of type Browser.
Location
Required. A String value. The URL to open in the browser. 
TargetFrame
Optional. A String value. The frame to which the URL will be sent.
Note: The frame name is specified in the NAME argument of the <FRAME> tag in the HTML source.
PostData
Optional. A String value. The data that accompanies a Post request
Headers
Optional. A String value. Any header data, such as cookies and content-type. 


Return Type
None 


Example

Navigate to a URL
Sub Navigate_Example()
'The following example uses the Navigate method to navigate to the
'Mercury Interactive Web site.

Browser("Mercury Tours").Navigate ("www.merc-int.com")

End Sub

WaitProperty

Description

Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

Important Information

This method is useful for test run synchronization. Unlike the Exist method, the WaitProperty method enables you to synchronize the test run based on a specific object property. For example, you can instruct QuickTest to wait for a particular string to appear in a static text control:
' Wait up to 30 seconds for the string "Ready" to appear in the "Status" text control.

Window("Test").Static("Status:").WaitProperty "text", "Ready", 30000
You can also use comparison objects to perform more complex value comparisons. For example, you can instruct QuickTest to wait until a specific property value is greater than the specified value.
An example of the syntax required when using a comparison object is: Object.WaitProperty "items count",micGreaterThan(8)
The following comparison objects can be used:
·                         micGreaterThan: Greater than; Specifies that QuickTest waits until the property value is greater than the specified value.
·                         micLessThan: Less than; Specifies that QuickTest waits until the property value is less than the specified value.
·                         micGreaterThanOrEqual: Greater than or equal to; Specifies that QuickTest waits until the property value is greater than or equal to the specified value.
·                         micLessThanOrEqual: Less than or equal to; Specifies that QuickTest waits until the property value is less than or equal to the specified value.
·                         micNotEqual: Not equal to; Specifies that QuickTest waits until the property value is not equal to the specified value.
·                         micRegExpMatch: Regular expression; Specifies that QuickTest waits until the property value achieves a regular expression match with the specified value. Regular expressions are case-sensitive and must match exactly. For example, 'E.*h' matches 'Earth' but not 'The Earth' or 'earth'.

When the types of the expected value and actual value do not match, the comparisons are performed as follows (in this order):
·                         Empty values: Empty values may be an uninitialized variable or field (which returns TRUE for the IsNull function in VBscript) or initialized to an empty value (which returns TRUE for the IsEmpty function is VBscript). When trying to compare two arguments when at least one is an empty value, the comparison assumes equality for two uninitialized arguments and for two empty arguments. Any other combination is considered unequal.
For example:
dim vEmpty
Object.WaitProperty “text”,micNotEqual
(vEmpty) 
will not wait for the timeout (because the 'text' property value is an empty string and the argument passed to micNotEqual is an empty value, and so micNotEqual finds them not equal and returns TRUE).
·                         String values: When trying to compare a string value with non-string value, the string value is converted to the non-string type and then compared. If the string value cannot be converted to the non-string type, the comparison assumes the values are not equal.
For example:
Object.WaitProperty “text”,micGreaterThan(8) will not wait for the timeout if the 'text' property value is '16' (because micGreaterThan finds 16 to be greater than 8 and returns TRUE), but will wait if the 'text' property value is 'a' (because 'a' cannot be converted to a number).
·                         Boolean values: When trying to compare a Boolean value with non-boolean value, the non-boolean value is converted to a boolean value and then compared. The conversion method assumes that any integer value other than '0' is TRUE, and that '0' alone is FALSE. If the conversion fails to produce a boolean value (for example, if the value is 'abc'), the comparison result will be FALSE (note that for the WaitProperty method this result would instruct QuickTest to keep waiting). If the conversion succeeds, the method compares the two boolean values according to the comparison logic.
·                         Other value types: When other value types do not match, they are compared under the assumption that different types are not equal (nor greater than or less than each other).

Syntax

object.WaitProperty (PropertyName, PropertyValue, [TimeOut])

Syntax Details

Argument
Description
object
A test object of type Browser. A test object of type Browser.
PropertyName
Required. A String value. The name of the property whose value is checked. 
PropertyValue
Required. A Variant value. The value to be achieved before continuing to the next step. 
TimeOut
Optional. A Long value. The time, in milliseconds, after which QuickTest continues to the next step if the specified value is not achieved. If no value is specified, QuickTest uses the time set in the Object Synchronization Timeout option in the Run pane of the Test Settings dialog box. 


Return Type

A Boolean value.  Returns:
TRUE---if the property achieves the value.
FALSE---if the timeout is reached before the property achieves the value.

Note: A FALSE return value does not indicate a failed step.

Example

Wait For an Edit Box to Become Enabled Using the Default Timeout 
Sub WaitProperty_Example2()
'The following example uses the WaitProperty method to wait for the
'Account edit box to be enabled before setting its value to 123.
'If it is still disabled after the test's
'Object Synchronization Timeout time has been exceeded, it will not
'perform the Set method.
If Browser("index").Page("index").WebEdit("Account").WaitProperty("disabled", 0) Then
    Browser("index").Page("index").WebEdit("Account").Set ("123")
End If
End Sub