Java GUI Application Automation
abstract This section details how to test Java Application. If you are not familiar with Sahi Pro, please see Quick Tutorial on Sahi Pro
- Before the starting the Java application, we need to attach Sahi's agent.
This can be done by passing -javaagent:...agent.jar to the java command which starts your application.
We recommend creating a batch file to invoke your jar file and modifying it like this:
Open the batch file which is being used to run the Java Application. Append the following lines in the batch file:
SET SAHI_JAVA_AGENT_PATH=<sahi_pro_path>\extlib\sahi\sahiagent.jar SET JAVA_TOOL_OPTIONS=-javaagent:"%SAHI_JAVA_AGENT_PATH%" ... java command to start your application ...
- To open Java Application from Sahi browser, Sahi Browser capability should be enabled.
- To pass arguments to a Java Application at runtime, create a batch file and launch the Java Application from command-line.
- Open a command prompt and cd to sahi/userdata/bin (or click on the "Bin" link on the Sahi Dashboard).
- For Windows: Invoke java_app.bat with the Java application jar file path to start the application
(Download and save the Java plication on local file system before hand).
D:\Sahi_Pro\userdata\bin>java_app.bat <java -jar applicationPath>
- For Linux: Invoke java_app.sh with the Java application jar file path to start the application
(Download and save the Java application on local file system before hand).
~/sahi_pro/userdata/bin>./java_app.sh <java -jar applicationPath>
- To Launch Sahi Controller, click the Desktop icon on the Sahi Dashboard. You can now start recording. Like normal Sahi, you can use CTRL-Hover to identify various elements on the Java Application.
- To use "Evaluate expression" on Java GUI applications, choose
- For script playback in Controller Playback tab, select Start Mode as "Java" before "Play".
To start a Java application from script, use
- To start a Java application _launchJavaApplication($javaApplicationPath) API.
infoTo pass arguments to a Java Application at runtime, create a batch file and use
- All code interactions with Java application will need to be preceded by _setMode("JAVA")