-
Notifications
You must be signed in to change notification settings - Fork 29
/
SnapshotHelper.js
58 lines (51 loc) · 1.94 KB
/
SnapshotHelper.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function wait_for_loading_indicator_to_be_finished()
{
try {
re = UIATarget.localTarget().frontMostApp().statusBar().elements()[2].rect()
re2 = UIATarget.localTarget().frontMostApp().statusBar().elements()[3].rect()
while ((re['size']['width'] == 10 && re['size']['height'] == 20) ||
(re2['size']['width'] == 10 && re2['size']['height'] == 20))
{
UIALogger.logMessage("Loading indicator is visible... waiting")
UIATarget.localTarget().delay(1)
re = UIATarget.localTarget().frontMostApp().statusBar().elements()[2].rect()
re2 = UIATarget.localTarget().frontMostApp().statusBar().elements()[3].rect()
}
} catch (e) {}
}
function captureLocalizedScreenshot(name) {
wait_for_loading_indicator_to_be_finished();
var target = UIATarget.localTarget();
var model = target.model();
var rect = target.rect();
var deviceOrientation = target.deviceOrientation();
var theSize = (rect.size.width > rect.size.height) ? rect.size.width.toFixed() : rect.size.height.toFixed();
if (model.match(/iPhone/))
{
if (theSize > 667) {
model = "iPhone6Plus";
} else if (theSize == 667) {
model = "iPhone6";
} else if (theSize == 568){
model = "iPhone5";
} else {
model = "iPhone4";
}
}
else
{
model = "iOS-iPad";
}
var orientation = "portrait";
if (deviceOrientation == UIA_DEVICE_ORIENTATION_LANDSCAPELEFT) {
orientation = "landscapeleft";
} else if (deviceOrientation == UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT) {
orientation = "landscaperight";
} else if (deviceOrientation == UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN) {
orientation = "portrait_upsidedown";
}
var result = target.host().performTaskWithPathArgumentsTimeout("/usr/bin/printenv" , ["SNAPSHOT_LANGUAGE"], 5);
var language = result.stdout.substring(0, result.stdout.length - 1);
var parts = [language, model, name, orientation];
target.captureScreenWithName(parts.join("-"));
}