forked from appium/appium
/
bootstrap.js
40 lines (35 loc) · 1.01 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import "lib/console.js"
#import "lib/instruments_client.js"
#import "appium/base.js"
// automation globals
var target = UIATarget.localTarget();
var mainWindow = target.frontMostApp().mainWindow();
var wd_frame = mainWindow;
var endpoint = 'http://localhost:4723/instruments/';
// safe default
target.setTimeout(1);
// let server know we're alive and get first command
var cmd = getFirstCommand();
UIATarget.onAlert = function(){
return true;
};
while(true) {
if (cmd) {
console.log("Got new command from instruments: " + cmd);
var result = eval(cmd);
if (typeof result === "undefined") {
result = {value: false};
console.log("Command executed without response");
}
if (typeof result.status === "undefined") {
console.log("Result is not protocol compliant, wrapping");
result = {
status: codes.Success.code,
value: result
};
}
cmd = sendResultAndGetNext(result);
} else {
throw new Error("Error getting next command, shutting down :-(");
}
}