Returning to the Calling Test - WinRunner

The treturn and texit statements are used to stop execution of called tests.

  • The treturn statement stops the current test and returns control to the calling test.
  • The texit statement stops test execution entirely, unless tests are being called from a batch test. In this case, control is returned to the main batch test.

Both functions provide a return value for the called test.

treturn

The treturn statement terminates execution of the called test and returns control to the calling test. The syntax is:

treturn [( expression )];

The optional expression is the value returned to the call statement used to invoke the test.

For example:
# test a
if (call test b() == "success")
report_msg("test b succeeded"); # test b
if (win_check_bitmap ("Paintbrush - SQUARES.BMP", "Img_2", 1))
treturn("success");

else
treturn("failure");

In the above example, test_a calls test_b. If the bitmap comparison in test_b is successful, then the string “success” is returned to the calling test, test_a. If there is a mismatch, then test_b returns the string “failure” to test_a.

texit

When tests are run interactively, the texit statement discontinues test execution. However, when tests are called from a batch test, texit ends execution of the current test only; control is then returned to the calling
batch test. The syntax is:

texit [( expression )];

The optional expression is the value returned to the call statement that invokes the test.

For example:

# batch test
return val = call help_test();
report msg("help returned the value" return val); #help test
call select menu(help, index);
msg = get text(4,30,12,100);
if (msg == "Index help is not yet implemented")
texit("index failure");
...

In the above example, batch_test calls help_test. In help_test, if a particular message appears on the screen, execution is stopped and control is returned to the batch test. Note that the return value of the help_test is also returned to the batch test, and is assigned to the variable return_val.

For more information on batch tests, see “Running Batch Tests.”


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

WinRunner Topics