Skip Headers
Oracle® Application Testing Suite OpenScript User's Guide
Version 9.01 for Microsoft Windows (32-Bit)

Part Number E15488-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

3 Creating and Modifying Scripts

This chapter explains the procedures for creating and modifying basic scripts in OpenScript. The module chapters provide additional information about creating scripts using the features and capabilities provided within specific modules.

Creating Repositories and Workspaces

Repositories and workspaces store project related script files and results log files. You can use repositories and workspaces to organize your various testing projects. OpenScript lets you create multiple workspaces.You can create repositories to organize the storage of your script projects.

A repository is the directory location where you store workspaces. Workspaces are user-specified subdirectories of the repository. OpenScript automatically appends an exclamation point to the directory name to identify the directory as a Workspace directory.

When you record and save scripts, or play back a script and save the log file, OpenScript stores the script or log file in the specified Workspace.

OpenScript initially uses the default Oracle Functional Testing for Web Applications repository and workspaces (C:\OracleATS\OFT). You can create your own repositories and workspaces using OpenScript.

Creating a Repository

To create a repository:

  1. Select OpenScript Preferences from the View menu.

  2. Expand the OpenScript node.

  3. Expand the General node.

  4. Select the Repository node.

  5. Click Add.

    This dialog box lets you specify the name and location of the repository to use to store script files.

  6. Enter a repository name. The name is required.

    Name: Enter any name to identify the repository.

  7. Enter the drive and directory location or click Browse to select the location to use for the repository.

    Location: Enter the drive and directory path to the repository or use the Browse button to select a location. The location must be a valid drive and directory path.

  8. Click OK to add the new repository to the list of repositories.

  9. Click OK to close the preferences.

When you create new a script project, you can select the repository to use to store the project.

Managing Repositories

To add, edit, or delete repositories:

  1. Select Manage Repositories from the Tools menu.

  2. Select the repository where you want to create the workspace.

  3. Click the Add, Edit or Delete buttons to manage repositories.

  4. Click Close when finished.

Managing Workspaces

When starting a new testing project, you should create a project-specific Workspace to store related files.

To create, rename, or delete workspaces:

  1. Select Manage Workspaces from the Tools menu. OpenScript opens a dialog box for managing Workspaces.

  2. Select the repository where you want to create the workspace.

  3. Click New, Rename, or Delete buttons to manage workspaces.

  4. Click Close when finished.

Managing Scripts

To rename or delete scripts:

  1. Select Manage Scripts from the Tools menu.

  2. Select the script.

  3. Click the Rename or Delete buttons to manage script files.

  4. Click Close when finished.

Creating a Script Project

You must create a script project to generate the basic structure that you can then customize.

To create a script project:

  1. Select New from the File menu.

  2. Expand a group node and select the type of script to create:

    Functional Testing (Browser/GUI Automation): The Functional Testing group contains the following script types:

    • Oracle EBS/Forms: This option lets you create a new script for automated functional testing of Oracle E-Business Suite and other applications that utilize Web and Oracle Forms components at the browser/gui level. The resulting script will contain the Initialize, Run, and Finish nodes. The Run node will contain recorded Web navigations based upon the defined Step Group preferences and the Web navigations and Forms actions performed during recording. You can edit the script tree or Java code to customize the script.

    • Siebel: This option lets you create a new script for automated functional testing of Siebel applications that utilize Siebel High Interactivity and Standard Interactivity/Web controls at the browser/gui level. The resulting script will contain the Initialize, Run, and Finish nodes. The Run node will contain recorded Web navigations based upon the defined Step Group preferences and the Web navigations performed during recording. You can edit the script tree or Java code to customize the script.

    • Web: This option lets you create a new script for automated functional testing of Web applications at the browser/gui level. The resulting script will contain the Initialize, Run, and Finish nodes. The Run node will contain recorded Web navigations based upon the defined Step Group preferences and the Web navigations performed during recording. You can edit the script tree or Java code to customize the script.

    General: The General group contains the following script types:

    • Java Code Script: This option lets you create a new automated test script using your own custom Java code through the OpenScript Eclipse IDE. A basic script structure contains only the Initialize, Run, and Finish nodes. You can edit the script tree or Java code to develop your own custom script.

    • Web Services: This option lets you create the basic structure of a Web Services script a new script for automated testing of Web Services at the SOAP/HTTP protocol level. A Web Services script structure contains only the Initialize, Run, and Finish nodes. You can use the WSDL Manager to add WSDL files and edit the script tree or Java code to customize the script. If you have a Web Services client application written already that communicates over HTTP and which communicates through a proxy, you can record the traffic using the OpenScript HTTP recorder.

    Load Testing (Protocol Automation): The Load Testing group contains the following script types:

    • Oracle EBS/Forms: This option lets you create a new script for load testing of Oracle E-Business Suite and other applications that utilize HTTP and Oracle Forms (NCA) protocols at the protocol level. The resulting script will contain the Initialize, Run, and Finish nodes. The Run node will contain recorded HTTP protocol navigations based upon the defined Step Group preferences and the navigations and Forms protocol for actions performed during recording. You can edit the script tree or Java code to customize the script.

    • Siebel This option lets you create a Siebel script structure of a new OpenScript script project. A Siebel script lets you record Siebel Web navigations using a browser for load testing Siebel applications. The resulting script will contain the Initialize, Run, and Finish nodes. The Run node will contain recorded HTTP protocol navigations based upon the defined Step Group preferences and the Web and Siebel navigations performed during recording. You can edit the script tree or Java code to customize the script.

    • Web/HTTP This option lets you create a new script for load testing of Web Applications at the HTTP protocol level. The resulting script will contain the Initialize, Run, and Finish nodes. The Run node will contain recorded Web navigations based upon the defined Step Group preferences and the Web navigations performed during recording. You can edit the script tree or Java code to customize the script.

  3. Click Next.

  4. Select the Repository and workspace where you want to store the script project.

    • Repository: Specifies the repository where the script project will be saved. Select a repository from the list or click the New button to open the OpenScript repository preferences and create a new repository.

    • Workspace: Specifies the workspace within the repository where the script project will be saved. Select a workspace from the list or click the New button to open a dialog box for creating a new workspace.

      The New Workspace dialog box lets you specify a new OpenScript workspace.

      • Name: Specifies the name of the new workspace.

  5. Enter a script name.

    • Script: Specify a name for the script project. The script name is required and must be unique.

    • Existing Scripts: List the names of the existing scripts in the workspace.

  6. Click Finish. For Java Code Scripts, a basic script tree will be created in the script view. You can edit the Java code in the code view. For module scripts, a script tree will be created in the script view. After you record the script, the tree view will contain the navigations and actions depending upon the type script.

Opening Existing Scripts

For existing scripts, the file concurrency control prevents multiple users from editing the same script. If you try to open a script that is in use by another user, the script copy wizard opens and you will be asked if you want to make a copy of the script and additional files.

Modifying Scripts

Once you have created a script project, you can customize the script for your specific testing purposes using the available menu options or editing your own code in the Java Code view.

Adding Step Groups to a Script

Step groups provide a way to group multiple procedures into a single reporting step.

To add a manual step group to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the step group.

  3. Select the Script menu and then select Step Group from the Add sub menu.

    This dialog box lets you specify or modify a step group node in a script tree.

  4. Enter a name for the Step Group.

    Title: Specify the title text of the step group. The title text will appear in the script tree.

  5. Enter any think time delay to add to the Step Group.

    Think time: Specify the amount of time in milliseconds to use as a think time delay for the step group.

  6. Click OK. The Step Group is added to the script tree.

To add a step groups to a script based upon preferences:

  1. Open or create a script project.

  2. Select OpenScript Preferences from the View menu.

  3. Expand the OpenScript node.

  4. Expand the Record node.

  5. Select the Step Groups node.

  6. Specify the step Group preferences and click OK.

  7. Select Create Step Groups from the Script menu. The Step Groups will be automatically added to the script tree.

  8. In the Java Code view, the step group consists of the code executed between beginStep and endStep:

    beginStep("Step Group 1", 10);
    
    {
    
            /**
    
             * Add code to be executed for the step group.
    
             */
    
            getLogger().info("Step Group 1");
    
    }
    
    endStep();
    
    

Adding a Delay to a Script

To add a delay to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the delay.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the General node and select Think Time.

    This dialog box lets you specify or modify a delay time in seconds.

  5. Enter a valid integer to use as the think time in seconds.

  6. Click OK. The Think node is added to the script tree.

  7. In the Java Code view, the think(time;) (the time is in seconds) statement will be added to the script code:

    think(10.0);
    
    

Adding a Log Message to a Script

To add a log message to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the log message.

  3. Select the Script menu and then select Message from the Add sub menu.

    This dialog box lets you specify or modify a log message in a script tree.

  4. Enter the message text.

    Message: Specify the text of the log message. The text will appear in the Console view on script playback.

  5. Click OK. The log message node is added to the script tree.

  6. In the Java Code view, the type("log message") method will be added to the script code:

    info("Message");
    
    warn("Message");
    
    fail("Message");
    

The log message text appears in the Console View when the script is played back.

Adding a For Statement to a Script

To add a For statement to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the For statement.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the Control Statements node and select For.

    This dialog box lets you specify or modify the For statement loop count.

  5. Enter a valid integer to use as the loop count.

    Loop Count: Specify the number of times to loop though the For statement.

  6. Click OK. The For node is added to the script tree.

  7. In the Java Code view, the for (int i=0; i < loop count; i++) statement will be added to the script code:

    for (int i=0; i < 10; i++)
    
    

Adding a Function to a Script

You can add your own custom functions to your script and specify the arguments to pass to the function.

To add a function to a script:

  1. Create a script project.

  2. Record a complete script.

  3. Select the Run node in the script tree.

  4. Select the Script menu and then select Other from the Add sub menu.

  5. Expand the General node and select Function.

    This dialog box lets you specify a custom function name with multiple arguments.

    Name: Specifies the name of the custom function. Click Add to define the names and data type of an argument.

    Argument: Lists the defined function arguments for the custom function.

    Type: Lists the data type for the defined argument for the custom function.

    Add: Opens a dialog box for defining a new argument for the custom function.

    Edit: Opens a dialog box for editing the selected argument.

    Delete: Removes the selected argument from the list.

    Up: Moves the selected argument up one place in the list.

    Down: Moves the selected argument down one place in the list.

  6. Enter the function name.

  7. Click Add.

    This dialog box lets you specify a custom function argument to use to pass data to the function.

    Name: Specify a name of the custom function argument (you may want to include the data type in the argument name so that it is indicated in the Substitute Variable list).

    Type: select the data type: String, Integer, Double, Long, or Boolean.

  8. Enter an argument name.

  9. Select the data type for the argument.

  10. Click OK.

  11. Click Add and add more arguments or click OK to add the function to the script. The function name node is added to the script tree.

  12. In the Java Code view, the public void function name statement will be added to the script code followed by the arguments with the data types:

    public void MyFunction(@Arg("argString") String argString,
    
          @Arg("argInt") int argInt,
    
          @Arg("argDouble") double argDouble,
    
          @Arg("argLong") long argLong,
    
          @Arg("argBool") boolean argBool)
    
       throws Exception {
    
  13. Add items into the Function. You can use the Tree View drag/drop or cut/paste features to move Tree View items to the function. You can use the Script Add option to add variable items to the function. You can also use the Code View to add custom code to the function.

To pass arguments into a function:

Define the variables to use to pass values to the custom function arguments somewhere in the script before where the Call Function statement will be placed in the script:

  1. Select the script node where you want to add variables.

  2. Select the Script menu and then select Other from the Add sub menu.

  3. Expand the Variables node and select Set Variable.

    This dialog box lets you define a variable in a script.

  4. Enter the variable name and value.

    • Name: Specify the name of the variable.

    • Value: Specify the value to assign to the variable.

  5. Enter a value or click the Substitute Variable icon to select a variable value to assign to the variable.

  6. Click OK.

  7. In the Java Code view, the getVariables().set() statement will be added to the script code followed by the variable name and value for each variable:

    getVariables().set("MyString", "String");
    
    getVariables().set("MyInt", "1");
    
    getVariables().set("MyDouble", "1234");
    
    getVariables().set("MyLong", "1234560");
    
    getVariables().set("MyBool", "True");
    

    The following is an example of a variable set to a Databank value:

    getVariables().set("MyString", "{{db.customer.FirstName,String}}");
    
  8. Select the Function node (your custom function name) in the script.

  9. Select the Script menu and then select Other from the Add sub menu.

  10. Expand the tree and select the item to add. For example Message under the General node or Set Variable under the Variables node.

  11. Click the Substitute Variable icon to select a custom variable or function argument. The Select Variable tree lists the custom function with all of is defined arguments.

  12. Select an argument for the custom function.

  13. Click OK.

  14. In the Java Code view, the message statement (info, warn or fail) or getVariables().set() statement will be added to the script code followed by the variable name and value for each variable:

    public void MyFunction(@Arg("argString") String argString,
    
          @Arg("argInt") int argInt,
    
          @Arg("argDouble") double argDouble,
    
          @Arg("argLong") long argLong,
    
          @Arg("argBool") boolean argBool)
    
       throws Exception {
    
          info("{{arg.argString}}");
    
          getVariables().set("MyArgString", "{{arg.argString}}");
    
          getVariables().set("MyArgInt", "{{arg.argInt}}");
    
          getVariables().set("MyArgDouble", "{{arg.argDouble}}");
    
          getVariables().set("MyArgLong", "{{arg.argLong}}");
    
          getVariables().set("MyArgBool", "{{arg.argBool}}");
    
    }
    

To call a custom function in a script:

  1. Select the node in the script tree here you want to call the function.

  2. Select the Script menu and then select Other from the Add sub menu.

  3. Expand the General node and select Call Function.

    This dialog box lets you specify a custom function to call and specify the argument values.

  4. Enter the argument data to pass to the custom function or click the Substitute Variable icon to select a custom variable or databank variable.

    • Function: Select the name of the custom function. The names of custom functions that were added to the script will appear in this list.

    • Arguments: A field for each custom function argument will appear for the selected function. Enter the argument value or click the Substitute Variable icon to select a custom variable or databank variable.

  5. Click OK.

  6. In the Java Code view, the callFunction statement will be added to the script code followed by the function name and arguments as String data types:

    callFunction("MyFunction", "MyStringArg");
    

    To pass data types other than String, enclose a defined variable name in double curly braces as follows, "{{VarName}}".

    callFunction("MyFunction", "{{MyString}}", "{{MyInt}}", "{{MyDouble}}", "{{MyLong}}", "{{MyBool}}");
    
    

Adding a Script to Run from a Script

To add a script to run to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the script to run.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the Expand the General node and select Run Script.

    This dialog box lets you specify the script to run from within another script.

  5. Select or clear the Use Absolute Path option. If you select Use Absolute Path, select the path and script using Browse next to the Script File field and skip to Click OK. If you clear Use Absolute Path continue the remaining steps.

    Use Absolute Path: When selected, the Script File field becomes enabled. Click Browse next to the Script File field to select the script path and file name.

  6. Select the repository and workspace.

    Repository: Lists the defined OpenScript repositories.

    Workspace: Lists the defined OpenScript workspaces.

  7. Select the script to run.

    Script: Lists the available OpenScript scripts in the selected repository and workspace.

    Script File: Specifies the absolute path and script name for a script when the Use Absolute Path option is selected. Click Browse to select the script path and file name.

  8. Select or clear the Sections of script to run option.

    Sections of script to run: Specifies which script sections to run during playback.

    • Initialize Section: When selected, the code in the Initialize section of the selected script to run is executed during playback. When cleared, the code in the Initialize section is skipped.

    • Run Section: When selected, the code in the Run section of the selected script to run is executed during playback. When cleared, the code in the Run section is skipped.

    • Finish Section: When selected, the code in the Finish section of the selected script to run is executed during playback. When cleared, the code in the Finish section is skipped.

  9. Click OK. The script name node is added to the script tree.

  10. In the Java Code view, the runScript(); statement will be added to the script code:

    runScript("repository", "workspace", "scriptName", initialize = true|false, run = true|false, finish = true|false);
    

    Example

    runScript("Default", "Default", "fmstocks1", true, true, true);
    

Adding a Set Variable to a Script

To add a Set Variable to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the set variable.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the Variable node and select Set Variable.

    This dialog box lets you set a variable value in a script.

  5. Enter the variable name and value.

    • Name: Specify the name of the variable.

    • Value: Specify the value to assign to the variable.

  6. Click OK. The Set variable = value node is added to the script tree.

  7. In the Java Code view, the getVariables().set("variable name", "value"); method will be added to the script code:

    getVariables().set("sVar_MyVar", "My_Value");
    

    If you want to set the variable with a value from an Oracle Functional Testing for Web Applications transform variable (i.e. a variable value contained in {{}} syntax), use the Transforms.transform method with the getVariables().set, as follows (requires HTTP module):

    http.solve("varTitle", "<TITLE>(.+)</TITLE>", "Page Title Error", false, Source.Html, 0);
    
    
    getVariables().set("sVar_MyVar", Transforms.transform("{{varTitle}}", getVariables()));
    
    

Adding Comments to Script Results

To add comments to script results:

  1. Open or create a script.

  2. Click the Code view tab.

  3. Add comments or warnings using one of the following code examples:

  • Using a step group:

  • beginStep("Any comment string", 0);
    
    {
    
    //The comment string appears in the Name column of the Results view.
    
    }
    
    endStep();
    
  • Using the getStepResult().addComment method:

  • //The comment string appears in the Summary column of the Results view
    
    getStepResult().addComment("Any comment string");
    
  • Using the getStepResult().addWarning method:

  • //The warning string appears in the Summary column of the Results view. 
    
    //addWarning overides addcomment.
    
    getStepResult().addWarning("Any warning string");
    
    

Adding Error Recovery to a Script

To add error recovery to a script:

  1. Open or create a script project.

  2. Select the script node where you want to add the log message.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the General node and select Error Recovery Action.

    Exception: Select the type of exception error. The list will vary depending upon the script type.

    Action: Select the error recovery action: Fail, Warn or Ignore.

  5. Click OK. The log message node is added to the script tree.

  6. In the Java Code view, the setErrorRecovery(scriptType.constant, ErrorRecoveryAction.action); method will be added to the script code:

    setErrorRecovery(BasicErrorRecovery.ERR_VARIABLE_NOT_FOUND, ErrorRecoveryAction.Fail);
    
    

Script Types

The following are the possible values for scriptType in the Java code statements:

BasicErrorRecovery (Basic module)

FormsErrorRecovery (EBS/Forms Functional module)

FTErrorRecovery (Generic functional module)

HttpErrorRecovery (HTTP module)

NcaErrorRecovery (EBS/Forms Load module)

UtilitiesErrorRecovery (Generic Utilities)

WebErrorRecovery (Web Functional module)

Constants

The following are the possible values for constant in the Java code statements:

BasicErrorRecovery (Basic module)

ERR_VARIABLE_NOT_FOUND

ERR_CREATE_VARIABLE_ERRORCODE

ERR_FILE_NOT_FOUND

ERR_SEGMENT_PARSER_ERROR

ERR_BINARY_DECODE

ERR_ENCRYPTION_SERVICE_NOT_INITIALIZED

ERR_GENERIC_ERROR_CODE

FormsErrorRecovery (EBS/Forms Functional module)

ERR_FORMS_FT_ERROR

FTErrorRecovery (Generic Functional Module)

ERR_FT_MATCH_ERROR

ERR_OBJECT_TEST_ERROR

ERR_TABLE_TEST_ERROR

HttpErrorRecovery (HTTP Module)

ERR_ZERO_LENGTH_DOWNLOAD

ERR_MATCH_ERROR

ERR_RESPONSE_TIME_ERROR

ERR_SOLVE_ERROR

ERR_HTML_PARSING_ERROR

ERR_INTERNET_INVALID_URL

ERR_INVALID_HTTP_RESPONSE_CODE

ERR_KEYSTORE_LOAD_ERROR

NcaErrorRecovery (EBS/Forms Load Module)

CONNECT_ERROR

MESSAGE_IO_ERROR

CONTROL_INITIALIZE_ERROR

UtilitiesErrorRecovery (Generic Utilities)

ERR_SQL_EXECUTE_ERROR

ERR_XML_PARSING_ERROR

ERR_CSV_LOADING_ERROR

WebErrorRecovery (Web Functional module)

ERR_RESPONSE_TIME_ERROR

ERR_WEBDOM_SOLVE_ERROR

ERR_WAIT_FOR_PAGE_TIMEOUT_ERROR

Actions

The following are the possible values for action in the Java code statements:

Fail

Ignore

Warn

Chaining Multiple Scripts

You can run multiple scripts from within a single script to chain playback of scripts together.

The procedure involves the following major steps:

  • Setting the browser preferences

  • Recording scripts

  • Creating a shell script

Setting the Browser Preferences

The browser preferences specify if a new browser will launch when recording a different script. Because the navigation sequence between multiple scripts is important, the same instance of the browser should run all scripts if the scripts are a continuation of each other. If each script is self-contained and there is no navigation between scripts, each script can launch its own browser and you can skip the Browser Preferences steps.

  1. Select Preferences from the View menu.

  2. Expand the General category and select Browsers.

  3. Clear the Always launch a new browser when recording a different script option.

  4. Click OK.

Recording Scripts

When recording scripts for chained playback, it is important to plan the start and stop points between scripts. This is especially true if session state needs to be maintained between scripts. All of the scripts must be of the same type.

  1. Create and record the first script, for example a Web Functional test log in script.

  2. Stop the recording but do not close the browser.

  3. Save the script.

  4. Create and record the next script. The navigation in this script should start from the point in the browser where the first script stopped.

  5. Stop the recording and save the script.

  6. Create and record any additional scripts to chain. The navigation in these script should start from the point in the browser where the previous script stopped.

Creating a Shell Script

The shell script is used to run the previously recorded scripts in sequence.

  1. Create a new script to use as the shell script.

  2. Select the script node where you want to add the first script. This could be either the Initialize or Run nodes.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the General node and select Run Script.

  5. Click OK.

  6. Select the Repository and Workspace names.

  7. Select the script to run.

  8. Click OK.

  9. Select the script node where you want to add the next script. This could be either the Initialize, Run, or Finish nodes.

  10. Select the Script menu and then select Other from the Add sub menu.

  11. Expand the General node and select Run Script.

  12. Click OK.

  13. Select the Repository and Workspace names.

  14. Select the next script to run.

  15. Click OK.

  16. Repeat the Add script steps for each additional script to run.

  17. Save and playback the shell script to verify the script navigations work together correctly.

  18. In the Java Code view, the runScript() methods will be added to the script code:

    runScript("Default", "Default", "Web1", true, true, true);
    
    runScript("Default", "Default", "Web2", true, true, true);
    
    

Moving Nodes in a Script

You can click and drag a node in the script tree view to move the node to another location in the script tree. For example, you move a step group node from the Run section to the Initialize section or move a navigation node.

To move script nodes in the script tree:

  1. Open or create a script project.

  2. Select the script node to move in the Tree View tab of the Script View.

  3. Click and drag the mouse to move the node in the script tree. The script tree shows an indicator line that points to the location in the script tree where the node will be moved.

  4. Release the mouse button when the indicator line is at the location where you want to move the script node.

When moving Step Groups between script sections (i.e. between Run and Initialize, etc.) you may need to move the node to the section node.

You can also switch to the code view and move lines of code manually.

Changing Text File Encoding

Before recording sites with international characters on an English OS, users should change the default character set encoding to a character set that supports the desired character set.

To change the text file encoding:

  1. Start OpenScript and select Developer Perspective from the View menu.

  2. Select Preferences from the Windows menu.

  3. Expand the General node.

  4. Select the Workspace node.

  5. Select the Other option under Text file encoding.

  6. Select desired text file encoding (i.e. UTF-8 for Japanese language Web sites, etc.).

  7. Click Close when finished.

Debugging Scripts

You can use features of the Eclipse IDE to debug scripts. For debugging purposes, it is not always necessary to switch to the Debug Perspective to debug a script. You can add views to the Tester Perspective, such as Breakpoints, Debug, and Expressions views. In most cases, you do not need to use the Outline, Variables, and Tasks views. This section provides tips for basic script debugging techniques.

Adding Views to the Tester Perspective

In some cases, you may want to add additional views to the Tester Perspective for debugging purposes. You select the view to open using the shortcut keys to get to the Show View window.

To open the Show View window:

  1. Press and hold the Shift and Alt keys, then press the Q key (Shift+Alt+Q).

  2. Press the Q key again. The Show View window opens.

  3. If necessary, expand the Debug tree.

  4. Select the View(s) you want to open:

    • Press and hold the Shift key and click to select multiple contiguous view names.

    • Press and hold the Ctrl key and click to select multiple non-contiguous view names.

  5. Click OK.

The selected views open in the Tester Perspective.

Note:

If you are in the Developer Perspective, you can add a view by selecting Show View from the Window menu and then selecting Other.

Adding Breakpoints to a Script

You can add breakpoints to the script Java Code to halt script execution at a specific line of code in the script.

To add a breakpoint to the script code:

  1. Create a script project.

  2. Record the script.

  3. In the Script view, click the Java Code tab.

  4. Double-click in the right-most column of the code view frame next to the code line where you want to add a breakpoint. The breakpoint indicator appears as a round dot in the frame. You can add as many breakpoints as needed.

  5. Play back the script.

    When you play back the script, code execution will stop at the breakpoint. The Confirm Perspective Switch message appears the when the code execution arrives at a breakpoint. Select the Remember my decision option if you do not want the message to appear again during future script playback.

  6. Click No to stay in the Tester perspective or Yes to switch to the Debug Perspective. You can use the following keyboard debug features to execute code while in debugging mode:

    • Single-step (F6) - executes the next line of code.

    • Step-into (F5) - opens the method/function class file.

      Note:

      Source code for the JRE or for the Eclipse IDE is not included with the product. When stepping into code, an editor may appear that does not contain source code. In this case, close the editor and resume script playback. You can use the Step-into feature to step into your own custom functions that you have added to a script.
    • Resume (F8) - resumes code execution to the script end or to the next breakpoint.

Adding a Java Exception Breakpoint

You can pause a script when any error occurs by adding a "Java Exception Breakpoint" to the Breakpoints list.

To add a Java Exception Breakpoint:

  1. Create a script project.

  2. Record the script.

  3. Open the Breakpoints view.

  4. Click the Add Java Exception Breakpoint icon on the Breakpoints View toolbar.

  5. Type "AbstractScriptException" and click OK to add this exception to the breakpoint list.

  6. Right-click on the breakpoint in the Breakpoints view and select Breakpoint Properties.

  7. Select the Suspend on Subclasses of this Exception option in the breakpoint properties and click OK.

During script playback, if an exception occurs, you can correct the problem and then continue script playback.

Pausing and Resuming Script Playback in Debug Mode

You can pause and resume script playback using the Debug view.

To pause and resume play back in Debug mode:

  1. Create a script project.

  2. Record the script.

  3. In the Script view, click the Java code tab.

  4. If necessary, add a Debug view to the Tester Perspective. If the Developer Perspective is open the Debug view should already be open.

  5. Play back the script.

  6. In the Debug view tree, select the Thread [Iterating Agent 1] thread and click the Pause toolbar button. The Thread [Iterating Agent 1] thread is the Virtual User's thread. You can ignore the others.

  7. In the Debug view tree, select script.run() and click the Resume toolbar button to resume playback.

    If you want to resume from a specific point in a script, comment out all lines before the current one, save the script, and then resume.

You can also execute portions of the script without having to comment out lines and restart the playback.

  1. Insert a breakpoint at the first line of the run() section.

  2. Playback the script. You can execute or inspect any line when playback halts a the breakpoint.

  3. Select the specific line(s) of code you want to playback, right-click and select Execute. You can modify the code and re-execute without having to save the script.

  4. Repeat the select code, right-click, Execute process until the script works the way you want it to work.

  5. Stop playback, or select the Resume button on the Debug view to replay from the breakpoint.

Inspecting and Changing Script Variable Values

You can inspect or watch script variable values to debug scripts. The script must be running or stopped at a breakpoint.

There is a difference between Java local variables and script variables. Java local variables are declared using standard Java syntax, such as String x or int i. Script variables are set using the OpenScript API methods, such as getVariables().set("someVariable", "123" or http.solve().

To inspect the value of a script variable:

  1. Create a script project.

  2. Record the script.

  3. In the Script view, click the Java Code tab.

  4. Add a breakpoint to the script.

  5. Play back the script.

  6. At the breakpoint highlight the script code containing the variable or type the following code and highlight the code:

    getVariables().get("someVariable")
    
  7. Right-click and select Inspect or Watch.

    • Inspect opens a pane that shows the variable (Shift-Alt-I adds the variable to the Expressions view).

    • Watch copies the variable to the Expressions view.

  8. To change the value of a script variable, type the following code:

    getVariables().set("someVariable", "newValue")
    
  9. Highlight the code.

  10. Right-click and select Execute.

    Note:

    You can also test individual web actions by pausing the script, selecting the code for the action to test, then right-clicking and selecting Execute (or pressing Ctrl+U).

Enabling Debug Logging

OpenScript provides debug logging capability using Jakarta Log4j.

To enable debug logging:

  1. Close OpenScript.

  2. Open the file log4j.xml located in C:\OracleATS\OpenScript.

  3. Locate the following section at the end of the file:

  4. <!-- ======================= -->
    
      <!-- Setup the Root category -->
    
      <!-- ======================= -->
    
    
            <!-- For production  -->
    
      <root>
    
       <priority value="WARN"/>
    
       <appender-ref ref="AGENTFILE" />
    
      </root>
    
            
    
            <!-- For debugging
    
      <root>
    
       <priority value="DEBUG"/>
    
       <appender-ref ref="AGENTFILE" />
    
       <appender-ref ref="CONSOLE" />
    
      </root>
    
            -->
    
  5. Move the ending comment brackets from:

  6. <!-- For production  -->
    
      <root>
    
       <priority value="WARN"/>
    
       <appender-ref ref="AGENTFILE" />
    
      </root>
    
            
    
            <!-- For debugging
    
      <root>
    
       <priority value="DEBUG"/>
    
       <appender-ref ref="AGENTFILE" />
    
       <appender-ref ref="CONSOLE" />
    
      </root>
    
            -->
    

    to:

    <!-- For production
    
      <root>
    
       <priority value="WARN"/>
    
       <appender-ref ref="AGENTFILE" />
    
      </root>
    
            -->
    
            
    
            <!-- For debugging -->
    
      <root>
    
       <priority value="DEBUG"/>
    
       <appender-ref ref="AGENTFILE" />
    
       <appender-ref ref="CONSOLE" />
    
      </root>
    
            
    
  7. Save the file log4j.xml and restart OpenScript.

  8. Run scripts.

The debug messages are stored in the file OpenScript.log located in <installdir>\OpenScript.

To turn off debugging, move the ending comment braces back to the original locations.