メインコンテンツまでスキップ

Javaサンプルスクリプト

この例では、EggdriveでJavaを使用する方法を示しています。Eggdriveの使用方法についての詳細は、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{
// クライアントを作成する
XMLRPCClient client= new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:5400"));
client.setConfig(config);

// セッションを開始する
String message = (String)client.execute("StartSession", new Object[]{"C:\\Users\\Documents\\EPF.suite"});
System.out.println(message);

// EggdriveからSUTへの接続を確立する
HashMap result = (HashMap)client.execute("Execute", new Object[]{"Connect \"localhost\""});
System.out.println(result.toString());

// Chromeを起動する (Chromeはそのアイコンの保存された画像です)
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());

// Eggplantのウェブサイトに移動する
result = (HashMap)client.execute("Execute", new Object[]{"TypeText(\"https://www.eggplantsoftware.com\" & returnKey)"});
System.out.println(result.toString());

// バナーテキストを待つ
result = (HashMap)client.execute("Execute", new Object[]{"WaitFor 10.0, (Text: \"Let's rid the world of bad software\")"});
System.out.println(result.toString());

// 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);
}
// セッションを終了する
finally {
try {
String message = (String)client.execute("EndSession",
new Object[]{});
System.out.println(message.toString());}
catch (XmlRpcException exc) {
{System.out.println(exc);
}
}
}