Create the script class

 

+

Search Tips   |   Advanced Search

 

Overview

After all model language elements are processed and the code language elements created, the code for the script class is generated.

The global script variables need to be declared at the top of the script, and their number and types are not known until all test elements are processed. The names of these variables and other associated information are gathered during the processing of the test element tree and are stored as temporary attributes of the test elements in the test model. The script class creation is accomplished by the ScriptDefinition class and is based on a separate script template.

The script template declares the imports and the script globals. It contains the parameters for script type-specific declarations and for methods creating and returning the test elements.

The creation of the top-level script class and test project involves the following steps:

  1. The language element tree and the top level script element are created.

  2. The generation of script text is performed and the text is stored in Eclipse storage units.

  3. The test project is configured, the class path is determined and updated, and the project is built.


Example

The following code represents an example of the script code structure:

package test;

import com.ibm.rational.test.lt.execution.http.IHTTPRequest;
...

public class Google_Test_C240F3CB2D546DE2A9BDE160BDA411D9 extends com.ibm.rational.test.lt.execution.protocol.impl.HTTPTestScript  {

    
    //GLOBAL DECLARATIONS
    private IBuiltInDataSource bds1 = new          
                       com.ibm.rational.test.lt.kernel.custom.impl.timestampdatasource();

    { builtInDCVars[50] = new BuiltInCorrelationVar(bds1);

        builtInDCVars[50].setProperty(1, "16");
        builtInDCVars[50].setProperty(2, "16"); }

    //TEST CLASS CONSTRUCTOR
    public Google_Test_C240F3CB2D546DE2A9BDE160BDA411D9(IContainer container, String  
                                                            invocationId) {

  super(container, "google", invocationId);

  setTimeoutScheme(IKTimeoutControl.CONTINUE);
  setArmEnabled(false);

  public void execute() {
         this.add(page_1(this));
         ...
         super.execute();
    }
  ......

 
    //page_1 CREATION METHOD
    private HTTPPage page_1(IContainer parent) {

      HTTPPage page = new HTTPPage(parent, "Google", .....)  {

          public void execute() {
                 this.add(request_1(this);
                 ... 
                 super.execute();
             }             
              .....
        };
        return page;
    }

    //request_1 CREATION METHOD
    private HTTPAction request_1(IContainer parent) {
  HTTPAction reqAction = new HTTPAction(parent, .....);
        .....
  harvestContainer_16.addHarvestInstruction ("resp_content", dcVars[50], ..);
  .....
  return reqAction;

    }

}


Related

  • Code generation


    Related tasks

  • Generate test code


    Related reference

  • Extension points for code generation
  • Code generation templates
  • New protocol extensions
  • Public APIs of codegen.core