Print Page | Close Window

Winrunner Conditional Statements

Printed From: One Stop Testing
Category: Testing Tools @ OneStopTesting
Forum Name: WinRunner @ OneStopTesting
Forum Discription: WinRunner is an automated functional GUI testing tool that allows a user to record and play back UI interactions as test scripts using a proprietary Test Script Language (TSL).
URL: http://forum.onestoptesting.com/forum_posts.asp?TID=7233
Printed Date: 30Nov2024 at 5:28pm


Topic: Winrunner Conditional Statements
Posted By: Mithi25
Subject: Winrunner Conditional Statements
Date Posted: 26Oct2009 at 1:05am
if/ Else Statement

An if/ else statement executes a statement if a condition is true; otherwise, it
executes another statement. It has the following syntax:

if ( expression )
statement1;
[ else
statement2; ]

For example, the if/ else statement below checks that the Flights button in the Flight Reservation window is enabled. It then sends the appropriate message to the report.


button_get_state (" FLIGHT", value);
if (value != ON)
    report_msg(" The Flights button was successfully enabled");
else
    report_msg(" Flights button was not enabled. Check that values for Fly From            
    and Fly To are valid");

Switch Statement:

A switch statement enables WinRunner to make a decision based on an
expression that can have more than two values. It has the following syntax:

switch (expression )
{
case case_ 1:
statements
case case_ 2:
statements
default: statement( s)
}
 switch (num)
{
    case 1: #First
    obj_check_gui(" Price:", "list1. ckl", "gui1", 1);
    break;
    case 2: #Business
    obj_check_gui(" Price:", "list2. ckl", "gui2", 1);
    break;
}
For Loop
A for loop instructs WinRunner to execute one or more statements a specified
number of times.

It has the following syntax:

for ( [ expression1 ]; [ expression2 ]; [ expression3 ] )
statement
For example, the for loop below selects the file UI_TEST from the File Name list in the Open window. It selects this file five times and then stops.

set_ window (" Open")
for (i= 0; i< 5; i++)
list_ select_ item (" File Name:_ 1", "UI_ TEST"); # Item Number 2

While Loop
 A while loop executes a block of statements for as long as a specified condition
is true.

It has the following syntax:

while ( expression )
statement ;
For example, the while statement below performs the same function as the for loop.

set_ window (" Open");
i= 0;
while (i< 5)
{
    i++;
    list_select_item (" File Name:_1", "UI_TEST"); # Item Number 2
}
 Do/While Loop:

A do/while loop executes a block of statements for as long as a specified condition
is true. A do/while loop has the following syntax:

do
statement
while (expression);
 For example, the do/while statement below opens and closes the Order dialog
box of Flight Reservation five times.

set_window (" Flight Reservation");
i= 0;
do
{
menu_select_item (" File; Open Order...");
set_window (" Open Order");
button_press (" Cancel");
i++;
}
while (i< 5);

Assignment 6             Using TSL  Functions:

  •  Start recording in Context Sensitive mode
  •  Open order #4
  •  Open the Fax Order dialog box
  •  Query the # Tickets field, Ticket Price field & Total field
  •  Click Cancel to close the Fax dialog box
  •  Stop recording and save the test
  •  Save the test as test6
  •  Create a function to check the total and report it to the result window
  •  Run the test
  •  Review the results


-------------
http://www.quick2sms.com - Send Unlimited FREE SMS to Any Mobile Anywhere in INDIA,
Click Here



Print Page | Close Window