Java Script

Agilitest is known for its broad coverage of various recent technologies in software development, and generally allows you to automate just about anything with a few clicks and graphically.

In some cases, however, it is useful to call external code to perform an environment-specific operation.

Agilitest can call a piece of Java code, passing in input variables and retrieving output parameters.

Of course, we recommend all the usual precautions when using Java external code, because while it can do everything, it can also have an unwanted impact on the SUT (System Under Test).

In terms of portability, the .ats code produced by Agilitest is transformed into Java for execution. You can therefore assume that the Java code you write will be portable to the various platforms supported by ATS.

Create a Java script

To begin with, you will generate the stub of your java code in Agilitest.

To do that, change the view to “Java ATS scripts” in the project explorer,

java script view

Click on the button to “Create a Java ATS script”.

create java script button

You can also create a Java script by clicking on “New component”, at the top left of the editor.

new component button

The editor opens a popup asking for the script name. Enter your script name and click "OK".

naming Java script

The editor opens a Java code editing window and, after the necessary and useful declarations, displays the function to be called: testMain().

Java source code


It is possible to pass parameters by value to your Java script.

To do this, click on the "Call script" action in your script.

call script action

Then, click on "Add parameter”.

add parameter button

Next, you can enter the values you want to pass to your script, and you can use all the possibilities offered by the Agilitest editor: use of variables, "hard" values, iterations on a .csv file…

To retrieve them from the Java code, you have the getParameter(int) function, which takes an integer corresponding to the index of the variable in the script call: getParameter(0) will return the first value passed in the parameters.


Results are retrieved symmetrically to the script call.

This requires the declaration of variables in the Agilitest editor, which will be of a type that cannot be modified (by the user).

To declare return variables, proceed as follows:

Declare a new variable in the variable management menu on the left of the editor.

create variable

Name the variable and drop it directly in the call script action.

name the variable

Agilitest will change the type of the variable to make it non-modifiable by the user (indicated by the orange coloured variable) and mark it as a “Returned variable” for the called Java script.

returned values

The variable can be used in your script for future operations.

To define a return value on the Java side, you have the returnValues() function, which takes all the values you wish to return:

returnValues("value1", "retvalue2", param1) ;

Obviously, the number of values returned must correspond to the number of variables declared in the Agilitest editor.

Code execution

If your test includes a Java script, it will be necessary to compile it before running the test. During compilation, any syntax errors will be highlighted.

Once your project has been compiled, you can run your test and Java actions as if they were standard Agilitest actions: step by step (action by action) and with the same execution mode, each Java action being executed in one go.

🔸 Warning

Before running your test, once the Java compilation has been completed, you must close all open channels to reload the compiled Java modifications.

If your Java code is a little complex, and you want to debug it, you can use step-by-step debugging provided you have assigned a Java debugging port in Agilitest and have an IDE such as eclipse or intelliJ.

Still require support?
Contact support