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

C# サンプルスクリプト

この例では、C#をEggdriveでどのように使用するかを示しています。Eggdriveの使用方法についての詳細は、Eggdriveの使用を参照してください。

using System;
using CookComputing.XmlRpc;
namespace Eggdrive
{
public class Response
{
public string Output { get; set; }
public double Duration { get; set; }
public object ReturnValue { get; set; }
public object Result { get; set; }
public override string ToString()
{
return String.Format("(Output={0}, Duration={1}, ReturnValue={2}, Result={3})",
this.Output,
this.Duration,
this.ReturnValue,
this.Result);
}
}
[XmlRpcUrl("http://localhost:5400")]
public interface EggdriveProxy : IXmlRpcProxy
{
[XmlRpcMethod("StartSession")]
string StartSession(string epfSuitePath);

[XmlRpcMethod("Execute")]
Response Execute(string command);

[XmlRpcMethod("EndSession")]
string EndSession(string arg = "");
}
class Program
{
static void Main(string[] args)

// Eggdriveプロキシを作成する

{
EggdriveProxy proxy =
XmlRpcProxyGen.Create<EggdriveProxy>();
try
{
// セッションを開始する
string message = proxy.StartSession("C:\\Documents\\EPF.suite");
Console.WriteLine(message);

// EggdriveからSUTへの接続を確立する
Response response = proxy.Execute("Connect \"localhost\"");
Console.WriteLine(response.ToString());

// Chromeを起動する(ここで、"Chrome"はそのアイコンの保存画像です)
response = proxy.Execute("DoubleClick \"Chrome\"");
Console.WriteLine(response.ToString());

// Chromeが読み込まれるのを待ち、検索フィールドをクリックして何かを入力する
response = proxy.Execute("Click (Text: \"Search Google or type a URL\", WaitFor: 10)");
Console.WriteLine(response.ToString());

// Eggplantのウェブサイトに移動する
response = proxy.Execute("TypeText(\"https://www.eggplantsoftware.com\" & returnKey)");
Console.WriteLine(response.ToString());

// バナーテキストを待つ
response = proxy.Execute("WaitFor 10.0, (Text: \"Let's rid the world of bad software\")");
Console.WriteLine(response.ToString());

// Chromeを終了する
response = proxy.Execute("TypeText(altKey, f4)");
Console.WriteLine(response.ToString());
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
// セッションを終了する
finally{
string message = proxy.EndSession();
Console.WriteLine(message);
}
}
}
}