Test Parameters as Global Variables
Below we consider different approaches to pass parameters to a Rapise test script. In Rapise we consider a parameter equivalent to a global variable. I.e. passing a parameter is the same as setting some variable to some specific value.
Suppose we have sample test ParamPassing.sstest. that has a file ParamPassing.user.js with two global variables defined:
var userLoginName="user1";
var userPassword="pass";
In addition to these two global variables, Rapise has several built-in global variables controlling script execution. Most of them start with the prefix ‘g_’ For example:
- g_iterationsCount - number of times to execute the test
- g_commandInterval - time in milliseconds to wait between execution of adjancent SeS(...) commands.
- g_entryPointName - name of function to use as test entry point. Default is "Test", i.e. Test - function is executed by default.
- g_reportFileName - path to a .trp file to save the execution report.
- And many many more.
Launching Test from Other Test
It is possible to execute one test from other in Rapise. Passing additional parameters is done in the following way:
function Test()
{
// Execute other test
Global.DoInvokeTest('c:\\tests\\paramtest.sstest',
{userLoginName: "User4", userPassword: "Secret4"});
}
See Global.DoInvokeTest and RVL.DoPlayTest for more details.
Launching Test from Command Line
If you have 64-bit Windows machine check out this article first.
It is recommended to use the SeSExecutor.js script to launch other tests using the following syntax:
cscript.exe "C:\Program Files\Inflectra\Rapise\Engine\SeSExecutor.js" C:\Tests\MyTest\MyTest.sstest
Passing additional params may be done by appending one or more command line parameters of the following type:
"-eval:g_testSetParams.<paramName>='<paramValue>'"
I.e.:
cscript.exe " C:\Program Files\Inflectra\Rapise\Engine\SeSExecutor.js" C:\Tests\MyTest\MyTest.sstest "-eval:g_testSetParams.userLoginName='User2'" "-eval:g_testSetParams.userPassword='secret2'"
will pass userLoginName='User2' and userPassword='secret2'
Launching Test from Test Set
The SeSExecutor.js script is responsible for launching test sets. In this case we pass the test set definition .js file rather than a single .sstest file.
Passing parameters to the test may be done in the same way as for a single test:
cscript.exe " C:\Program Files\Inflectra\Rapise\Engine\SeSExecutor.js" C:\Tests\MyTestSet.js "-eval:g_testSetParams.userLoginName='User3'" "-eval:g_testSetParams.userPassword='secret3'"
will pass userLoginName='User3' and userPassword='secret3'
See Running Rapise test sets without third-party tools for more details.
Launching Test from SpiraTest
You can pass parameters from the SpiraTest test management system using the RapiseLauncher application that comes with Rapise. As described in the Using Parameterized Test Cases section, you simply define test case parameters in SpiraTest with the same names as the Rapise global variables. Then when you execute the test cases, the values of the parameters stored in SpiraTest are passed to Rapise.
Note: SpiraTest before version 5.0 only supports lower-case parameters, you need to make sure that the global variables in Rapise are all lower-case:
g_userName // will not work with SpiraTest
whereas
g_user_name // will be accessible from SpiraTest
SpiraTest 5.0 and above does not have this limitation.
Passing Parameters via File
Currently there is no explicit ways of passing parameters from MbUnit or NUnit test to a Rapise test. However it is not hard to make this possible by passing parameters through a file. I.e. in Rapise:
Test.js
function Test()
{
eval(File.Include("c:\\temp\\params.js"));
Tester.Message( "Login:"+userLoginName+" pass:"+userPassword);
// Other test logic goes here.
// ...
}
Where eval(File.Include("c:\\temp\\params.js")) simply includes some file considering it as a valid JavaScript code. The global variables with default values of the input parameters are then defined in Test.user.js as follows:
var userLoginName="user1";
var userPassword="pass";
So all we need is to prepare the params.js from where we execute the test. In this case values defined in Test.user.js get overriden with values from c:\temp\params.js.
Launching Test from NUnit or MbUnit
We write the parameters to a file in method PrepareParams just prior launching the test:
private void PrepareParams(string path, string userLogin, string userPassword)
{
System.IO.StreamWriter sw = System.IO.File.CreateText(path);
sw.WriteLine("userLoginName='"+userLogin+"';");
sw.WriteLine("userPassword='"+userPassword+"';");
sw.Close();
}
[SeSNUnitTest(@"c:\Tests\ParamPassing\ParamPassing.sstest")]
public void TestWithParamPassing()
{
PrepareParams(@"c:\Temp\params.js", "NUnitUser", "NUnitPassword");
// Now execute test as usual
// ...
}