programming

Programming Operations

Programming Statements Overview

Programming statements can contain:
Test object operations. These are methods and properties defined by QuickTest. They can be operations that a user can perform on an object, operations that can retrieve or set information, or operations that perform operations triggered by an event.
Native operations. These are methods and properties defined within the object you are testing, and therefore are retrieved from the run-time object in the application.
VBScript programming commands. These affect the way the test runs, such as Conditional Statements and Synchronization Points. These are often used to control the logical flow of a test.
Comments. Use comments to explain sections of your tests to improve readability and to make them easier to update.

Step Generator
The Step Generator enables you to add steps by selecting from a range of context-sensitive options and entering the required values.


Conditional Statements
The If...Then...Else statement is used to evaluate whether a condition is true or false and, depending on the result, to specify one or more statements to run.

operators are available: less than , greater than or equal to >=, not equal , and equal =.

The statement has the following syntax:
If condition Then
 statements
[Else elsestatements]

End If

With Statements
With statements make your script (in the Expert View) more concise and easier to read by grouping consecutive statements with the same parent hierarchy.
The With statement has the following syntax.
With object
statement
statement
statement
End With

Test Synchronization
You can handle these anticipated timing problems by synchronizing your test to ensure that QuickTest waits until your application is ready before performing a certain step.
There are several options that you can use to synchronize your test:
You can insert a synchronization point, which instructs QuickTest to pause the test until an object property achieves the value you specify. When you insert a synchronization point into your test, QuickTest generates a WaitProperty statement in the Expert View.
You can insert Exist or Wait statements that instruct QuickTest to wait until an object exists or to wait a specified amount of time before continuing the test.Exist statements return a boolean value indicating whether or not an object currently exists. Wait statements instruct QuickTest to wait a specified amount of time before proceeding to the next step.
You can modify the default amount of time that QuickTest waits for a Web page to load.To modify the amount of time that QuickTest waits for a Web page to load, change the Browser Navigation Timeout in the File > Settings > Web pane.
When working with tests, you can increase the default timeout settings for a test to instruct QuickTest to allow more time for objects to appear. To modify the maximum amount of time that QuickTest waits for an object to appear, change the Object Synchronization Timeout in the File > Settings > Run pane.

Message Statements
You can generate messages in your test that are displayed in the Run Results Viewer. You can also choose to display messages on screen while running your test.

Test-specific messages example:
Reporter.ReportNote "This test was run from 12.34.56.89 using a wireless connection."

Step-specific messages example:
Reporter.ReportEvent micFail, "Password edit box", "Password edit box does not exist"

Displaying Messages During the Run Session

Use the MessageBox VBScript function in your test to display information during the run session.

Use the Print Utility statement in your test to display information in the QuickTest Print Log window


Tasks
How to Insert Steps Using the Step Generator
Step Generator Category
Test Objects. Enables you to select a test object and operation for the step (for tests only).
Utility Objects. Enables you to select a Utility object and operation for the step.
Functions. Enables you to select a function for the step from the available library functions (tests only), VBScript functions, and internal script functions.


Get item count and all items from fromPort object and print out on the Log window.
fromPortItemsCount = Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty("items count")
allFromPortItems = Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty( "all items")

Print allFromPortItems

How to Insert Conditional Statements from the Keyword View

Add checking if selected city is on the list and report error is not to the Result Viewer:

selectFromPort=DataTable("fromPort", dtGlobalSheet)

selectFromPortExist= InStr (1, allFromPortItems, selectFromPort)
If selectFromPortExist Then
 Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select DataTable("fromPort", dtGlobalSheet)
else
  
 Reporter.ReportEvent micFail, "Select From Port", "The city is not on the From Port list. " & "In the datatable: " & selectFromPort &";  City on the From Port List: " &allFromPortItems
End If

How to Insert Loop Statements In the Keyword View
Insert a loop statement to print out city list
If debugMode="Y" Then
 For i = 1 To fromPortItemsCount  Step 1
  Print Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetItem(i)
 Next
End If

How to Generate With Statements for Your Test
Instruct QuickTest to generate With statements while recording:General pane > Automatically generate "With" statements after recording.
Generate With statements for existing actions in the Expert View: Edit > Advanced > Apply "With" to Script.

Add Synchronization Point:

Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("banner2").WaitProperty "visible", ture, 10000

Insert Report:

Insert a report statement and taking pictures if failed.


登录后才可评论.