This is an old revision of the document!
TestOptimal agent in java can be run in standalone mode or included in other test automation tools that support java scripting like IBM Rational Robot and Functional Tester or Borland SilkTest.
Creating an agent in java is quite simple as the download package (agent.jar) already includes a java class which implements the API to TestOptimal server.
Below is an example of a java agent using the provided TestOptimalAgent class:
... // creates the agent object. // If you are not using log4j, then pass null instead. // localhost and 8888 are TestOptimal server host and port# // Demo_RemoteTrigger is the name of the model to be executed // last 2 params are # of retries on any communication errors // and # of milliseconds delay between retries TestOptimalAgent agent = new TestOptimalAgent (log4jObj, "localhost", 8888, "Demo_RemoteTrigger[[edit=RemoteTrigger|?]]", 5, 2000); // Execute the model, the params are user id and password // to access the model. Pass blank "" if the security is not enabled. If the model is already started, the following execModel() and sleep() are not needed. agent.execModel("", ""); // sleept for 5 sec to model to wait for the model to start Thread.sleep(5000); // obtain an agent id from the server. You may attach multiple agents // in which case you would create multiple agent objects and have // each agent run in a separate thread. String agentID = agent.attachToServer(); RemoteCmd nextRemoteCmd = null; // loop until no more remote command is received from the server while (true) { // obtain the next command from the server // pass nextRemoteCmd to have the execution results of last // remote command to be sent back to the server. nextRemoteCmd = agent.getNextCmd(nextRemoteCmd); // if no remote command is received, break the loop if (nextRemoteCmd==null) { break; } // optionally set the command executing for measuring performance nextRemoteCmd.setExecuting(); // add your logic to execute remote command received in nextRemoteCmd. ... // set the command execution status and results which will be // be sent back to the server to be stored with the remote command. nextRemoteCmd.setExecCompleted("exec results here"); } // stop the model execution. If multiple agents are used, then // the model should not be stopped until the last agent has completed. agent.stopExec(); // save the execution result to be reviewed later using TestOptimal Browser. agent.saveStat("from java agent xyz"); // print out the execution summary System.out.println("Execution result: " + agent.getExecSummary()); // close the model agent.closeModel(); ...
The download package includes an example java agent. You may run this demo by running a batch file startDemoRemoteAgent.bat.
(Release 3.0)