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.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 = ["Web"];

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.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 = ["Web"];

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.