Passing parameters to the callScript method

This topic describes how to use the different signatures of the callScript method to pass data from one script to another.

The example uses two different Functional Test scripts:

  • TheCaller, which calls another script and passes parameters
  • TheCalled, which receives the parameters and prints them to System.out

TheCaller script uses three different versions of the callScript method:

  • Without additional parameters: This is the default usage of the callScript method, which will execute the specified script.
callScript("TheCalled");
  • With additional string array parameter: An array of strings is used to pass string parameters to the called script.

String[] dataToPass = new String[4];
...
callScript("TheCalled",dataToPass);
  • With additional object array parameter: An array of objects is used to pass different object type parameters to the called script.

Object[] objdataToPass = new Object[4];
...
callScript("TheCalled",objdataToPass);

The TheCaller script was recorded as follows:


import resources TheCallerHelper;               
                
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;

/**
* Description : Functional Test Script
* @author Administrator
*/

public class TheCaller extends TheCallerHelper
{
/**
	 * Script Name   : TheCaller
	 * Generated     : Jul 14, 2006 5:13:02 PM
	 * Description   : Functional Test Script
	 * Original Host : WinNT Version 5.1  Build 2600 (S)
	 * 
	 * @since  2006/07/14
   * @author Administrator
*/
public void testMain (Object[] args)
{
    
    callScript("TheCalled");
    
    String[] dataToPass = new String[4];
    dataToPass[0] = "this";
    dataToPass[1] = "is";
    dataToPass[2] = "really";
    dataToPass[3] = "cool";
    
    callScript("TheCalled",dataToPass);
    
    Object[] objdataToPass = new Object[4];
    objdataToPass[0] = new String("Thought the previous was cool?");
    objdataToPass[1] = "Take this one!";
    objdataToPass[2] = new Float(0.02);
    objdataToPass[3] = new Integer(4711);
    
    callScript("TheCalled",objdataToPass);
}
}

The TheCalled script uses a simple loop to print the received parameters to System.out:


import resources.TheCalledHelper;

import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
/**
* Description : Functional Test Script
* @author Administrator
*/

public class TheCalled extends TheCalledHelper
{
/**
	 * Script Name   : TheCalled
	 * Generated     : Jul 14, 2006 5:13:02 PM
	 * Description   : Functional Test Script
	 * Original Host : WinNT Version 5.1  Build 2600 (S)
	 * 
	 * @since  2006/07/14
	 * @author Administrator
*/
public void testMain (Object[] args)
{
    if (args.length < 1)
    {
        System.out.println( "Expected at least 1 arg, but I got:
             "+args.length);
        return;
    }
    else
    {
        System.out.println( "Got: "+args.length+" args");
    }
    
    for (int i = 0; i < args.length; ++i)
    {
        System.out.println( " arg["+i+"] = "+args[i]);
    }
}
}