この 2 つのタスクを分離するには、(たとえば) REST クライアントを Android で、サーバーをデスクトップで実現する必要があります。
- クライアントはサーバーに接続する必要があります
- サーバーはクライアントに ping を送信し、クライアントは彼にスクリーンショットを送信します。おそらく、テストで別のスレッドを作成する必要があります。
クライアントは次のことを行う必要があります: スクリーンショットを撮る必要がある場合:
Object res = null;
res = new File(takeScreenShot(solo));
それで
public static String takeScreenShot(Solo _solo) {
solo = _solo;
String dir = "/sdcard/Robotium-Screenshots/";
String fileName = "screenshot";
java.io.File file = new java.io.File(dir, fileName);
if (file.exists()) {
file.delete();
}
solo.takeScreenshot(fileName);
solo.sleep(2000);
return "/sdcard/Robotium-Screenshots/" + fileName + ".jpg";
}
送信する必要があります
service.sendScreen(file);
そしてあなたのサービスでは、次のようにsmthngを行います:
public static JSONObject sendScreen(final File file) {
JSONObject res;
String response;
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(host + "/" + methodName);
MultipartEntity entity = new MultipartEntity();
entity.addPart("file", new FileBody(file));
httppost.setEntity(entity);
try{
response = httpclient.execute(httppost, responseHandler);
res = (JSONObject) JSONValue.parse(response);
}
catch(IOException e)
{
res = null;
e.printStackTrace();
}
return res;
}
スクリーンショットを解析する C# のコードの例を次に示します。
public void StepError(Stream stream)
{
var result = new DCStepErrorResponce();
const string imageName = "file";
string fullFileName = String.Empty;
var parser = new MultipartFormDataParser(stream);
if (parser.Files.Any(file => file.Name == imageName))
{
Stream data = parser.Files.First(file => file.Name == imageName).Data;
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "HFAutomationTesting", "Temp", "ScreenShots");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
do
{
string fileName = String.Format("{0:yy_MM_dd_HH_mm_ss_ffff}.jpg", DateTime.Now);
fullFileName = Path.Combine(path, fileName);
} while (File.Exists(fullFileName));
var fileToUpload = new FileStream(fullFileName, FileMode.Create);
byte[] bytearray = ToByteArray(data);
fileToUpload.Write(bytearray, 0, bytearray.Length);
fileToUpload.Close();
fileToUpload.Dispose();
}
}
C# で REST サーバーを実現してデバッグするだけです。