Agilitest is known for its broad coverage of various recent technologies in software development, and generally allows you to automate just about anything that can be automated in a few clicks and graphically.
In some cases, however, it is useful to call external code to perform a specific operation specific to the customer environment.
We will see in this article how Agilitest can call a piece of java code, passing input variables and retrieving output parameters.
Obviously, we recommend all the usual precautions in the use of external code java, because as it allows to do everything, it can also have an unwanted impact on the SUT (System Under Test).
In terms of portability, the .ats code that Agilitest produces is transformed into java for execution. You can therefore consider that the java code that you will write will be portable on the various platforms supported by ATS.
What, write some code!
Let's go !
For starters you will generate the stub of your java code in Agilitest by doing the following:
- In the Agilitest Explorer, select the java directory in src / main at the same level as your .ats files
- Right-click and select: New java script.
- The editor opens a popup to request the name of the script, enter the name of your script and click OK.
- The editor then opens a java code editing window and, after the necessary and useful declarations, displays the function that will be called: testMain().
public class test extends ActionTestScript{
public void testMain() { }
}
Parameters
It is possible to pass parameters by value to your java script.
To do this, you must click on "call the script" or on the small pencil that appears when you hover over the action, then click on "add a parameter".

Then you can enter the values you want to pass to your script, and you can use all the possibilities offered by the Agilitest editor for that: use variables, values in "hard", iterations on a .csv file.
To retrieve them on the java code side, you have the function getParameter(int), which takes an integer corresponding to the index of the variable in the call of the subscript: getParameter(0) will return the first value passed in settings.
String param1 = getParameter(0).toString();
int param2 = getParameter(1).toInt();
double param3 = getParameter(2).toDouble();
boolean param4 = getParameter(3).toBoolean();
Recovery of results
The results are retrieved symmetrically on the call.
It requires the declaration of variables in the Agilitest editor, which will be of the unmodifiable type (by the user).
To declare return variables, do the following:

- Declare a new variable in the variable management menu in the left-hand side of the editor.
- The type will be modifiable by default (violet).
- Name this variable
- Drop it directly into the subscript call action
- Agilitest will change the type of variable to make it unmodifiable by the user (orange) and indicate it as a return value from the java call
- Subsequently, you can use this variable in your script

To set a return value on java side, you have the function returnValues() which takes all the values you want to return:
returnValues("value1", "retvalue2", param1);
Obviously, the number of returned values must match the number of variables declared on the Agilitest editor side.
Exécution of the code
If your test includes a Java script, it will be necessary to compile it before running the test. At the time of this compilation, your potential syntax errors will be highlighted. You can find out more about the compilation of tests and the configuration of the executions.
Once your project is compiled, you will be able to run your test, and the java actions as if it were Agilitest's standard actions: step-by-step (Agilitest action by Agilitest action) and mode run in the same way, with each java action running in one go.
If your java code is a little complex, and you want to debug it, step by step will be possible provided you have assigned a Java debug port in agilitest and have an eclipse or intelliJ type IDE.