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.
To be able to run a specific code in a test, write your own
JavaScript code and insert the custom JavaScript file as a new test step in your test
script. For example, you might want to run your own JavaScript snippet for retrieving
data from the application, doing some actions within the application, or validating some
complex logical actions within the application.
Copy the JavaScript file with .js extension to the required project folder of
your workspace.
Double-click the test to open it from the Test Navigator
view in Test UI.
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).
The Select JavaScripts dialog is displayed.
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.
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.
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.
Note: You can also delete the added JavaScript file by
clicking the icon, or edit the file by clicking the link to open the file in an
editor screen.
Optional: Click Update to add one more JavaScript file.
Save the test.
Run the test.
The JavaScript custom code is executed within the Web application.
You have added custom JavaScript code as a test step in a
Web UI test.