Knowledge Base Article

Home Page > Knowledge Base > Rapise

Article Using Global.DoInvokeTest() to pass parameters between tests

by Adam S on Wednesday, October 31, 2012

Sometimes you want a test script to be able to call another sub-test as part of its operation. You can do this using the Global.DoInvokeTest('path to test', [parameters]); function. This articles provides a more detailed example for doing this.

The high-level information can be found on our website at: https://www.inflectra.com/Rapise/Guides.aspx?feature=Passing-Test-Parameters

For this example we shall have a Parent test called (ParentTest.sstest) call a child test (called ChildTest.sstest) and pass some parameters and also check the pass/fail status of the called test.

The child test consists of a simple recording against the sample Library Information System website (http://www.libraryinformationsystem.org) and has the following script:

Contents of ChildTest.sstest.js

function Test(params)
{
 //Set the defaults and override if we have parameters passed-in
 g_username = 'librarian';
 g_password = 'librarian';
 if (params.username)
 {
  g_username = params.username;
 }
 if (params.password)
 {
  g_password = params.password;
 }

 //Log out the variables
 Tester.Message('g_username: ' + g_username)
 Tester.Message('g_password: ' + g_password)
 
 //Click on Log In
 SeS('Log_In').DoClick();
 //Set Text librarian in Username:
 SeS('Username_').DoSetText(g_username);
 //Set Text librarian in Password:
 SeS('Password_').DoSetText(g_password);
 //Click on ctl00$MainContent$LoginUser$LoginButton
 SeS('ctl00$MainContent$LoginUser$Logi').DoClick();
 Global.DoSleep(1000);
 //Click on Log Out
 SeS('Log_Out').DoClick();
 
 //Close the browser
 Global.DoKillByName('iexplore.exe');
 
 //Set the test return value for the parent test
 g_testPassed = testResult;
}

g_load_libraries=["%g_browserLibrary:Internet Explorer HTML%", "DOM GWT", "DOM YUI"];

Notice how the main Test() function has an additional variable called "params", that will contain a Javascript object collection of variables and values. We will pass through two variables, "username" and "password".

Also notice how we have sent the return value automatically by using the g_testPassed = testResult; command. g_testPassed is a special built-in Rapise variable used to send back the results to the parent test and testResult is an internal variable containing the result of the current test.

Now, the code for the calling parent test is as follows:

Contents of ParentTest.sstest.js

//Calls the child test with a different login/password
function Test()
{
 var params = { username: 'borrower', password: 'borrower' };
 var result = Global.DoInvokeTest('..\\ChildTest\\ChildTest.sstest', params);
 Tester.Assert('Result from sub-test', result, 'Result was ' + result)
}

g_load_libraries=["%g_browserLibrary:Internet Explorer HTML%", "DOM GWT", "DOM YUI"];

Notice how we pass the object collection of parameter names and values to the child test and how we get the pass/fail result from the Global.DoInvokeTest(...) function.

Attached to this article is the full source code as a zipfile.

Attachments
Article Info
Last Updated: 10/31/2012
Article ID: KB25
# Views: 1557
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.