Adding custom JavaScript code as a test step in a Web UI test

You can manually add JavaScript files (*.js) with defined functions as a test step in the Web UI test.

Procedure

  1. Copy the JavaScript file with .js extension to the required project folder of your workspace.
  2. Double-click the test to open it from the Test Navigator view in HCL OneTest UI.
  3. Select one of the following options:
    • Select the Launch application node, and then click Add > Custom Code (JavaScript).
    • Select a step, and then click Insert > Custom Code (JavaScript).
    Right-click in any test step and select Custom Code choice

    The Select JavaScripts dialog is displayed.

  4. Select a JavaScript file under the project name to be added to the test step, and then click OK.
    The file is displayed as a link in JavaScripts in the Custom Code (JavaScript) Details pane. A new test step is added to the test script. If you selected the Launch application node, the new step is inserted as the last step in the script, and if you selected a test step, the new step in inserted before the selected step.
  5. Specify the JavaScript method name to be executed in the Method field, and optionally provide the description.
    When a method name is provided, the test step is named Custom Code (JavaScript):method-name.
    Test step added with custom code (JavaScript) including method name if any.
  6. Specify the parameters in the Arguments field if the JavaScript method has some parameters to be added by using one of the following options:
    • Click Text to enter the static text as an argument, and then click OK.
    • Click Add to select the available data source arguments, datasets, test variables, or java custom code as a parameter to the JavaScript method, and then click Select. You must have created the variable or dataset, and added a return value.
    JavaScript Custom code details
    Note: You can also delete the added JavaScript file by clicking the delete icon, or edit the file by clicking the link to open the file in an editor screen.
    Variable and dataset arguments
  7. Optional: Click Update to add one more JavaScript file.
  8. Save the test.
  9. Run the test.
    The JavaScript custom code is executed within the Web application.

Results

You have added custom JavaScript code as a test step in a Web UI test.