メインコンテンツまでスキップ
バージョン:23.4

Java Example Script

This example shows how you can use Java in Eggdrive. For more information about how to use Eggdrive, see Using Eggdrive.

package io.eggplant.eggdrive;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class App
{
public static void main (String [] args)
{
XMLRPCClient client= new XmlRpcClient);
try{
// Create the client
XMLRPCClient client= new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:5400"));
client.setConfig(config);

// Start the session
String message = (String)client.execute("StartSession", new Object[]{"C:\\Users\\Documents\\EPF.suite"});
System.out.println(message);

// Establish a connection from Eggdrive to a SUT
HashMap result = (HashMap)client.execute("Execute", new Object[]{"Connect \"localhost\""});
System.out.println(result.toString());

// Launch Chrome (where, Chrome is a saved image of its icon)
result = (HashMap)client.execute("Execute", new Object[]{"DoubleClick \"Chrome\""});
System.out.println(result.toString());
result = (HashMap)client.execute("Execute", new Object[]{"Click (Text: \"Search Google or type a URL\", WaitFor: 10)"});
System.out.println(result.toString());

// Go to the Eggplant website
result = (HashMap)client.execute("Execute", new Object[]{"TypeText(\"https://www.eggplantsoftware.com\" & returnKey)"});
System.out.println(result.toString());

// Wait for the banner text
result = (HashMap)client.execute("Execute", new Object[]{"WaitFor 10.0, (Text: \"Let's rid the world of bad software\")"});
System.out.println(result.toString());

// Quit Chrome
result = (HashMap)client.execute("Execute", new Object[]{"TypeText(altKey, f4)"});
System.out.println(result.toString());

}catch (XmlRpcException exc){
{System.out.println(exc);
}catch (MalformedURLException exc) {
{System.out.println(exc);
}
// End the session
finally {
try {
String message = (String)client.execute("EndSession",
new Object[]{});
System.out.println(message.toString());}
catch (XmlRpcException exc) {
{System.out.println(exc);
}
}
}