-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEarlGreyImpl.js
101 lines (84 loc) · 3.69 KB
/
EarlGreyImpl.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
This code is generated.
For more information see generation/README.md.
*/
function sanitize_uiDeviceOrientation(value) {
const orientationMapping = {
landscape: 3, // top at left side landscape
portrait: 1 // non-reversed portrait
};
return orientationMapping[value];
}
class EarlGreyImpl {
/*Provides the file name and line number of the code that is calling into EarlGrey.
In case of a failure, the information is used to tell XCTest the exact line which caused
the failure so it can be highlighted in the IDE.
@param fileName The name of the file where the failing code exists.
@param lineNumber The line number of the failing code.
@return An EarlGreyImpl instance, with details of the code invoking EarlGrey.*/
static invokedFromFileLineNumber(fileName, lineNumber) {
if (typeof fileName !== "string") throw new Error("fileName should be a string, but got " + (fileName + (" (" + (typeof fileName + ")"))));
if (typeof lineNumber !== "number") throw new Error("lineNumber should be a number, but got " + (lineNumber + (" (" + (typeof lineNumber + ")"))));
return {
target: {
type: "Class",
value: "EarlGreyImpl"
},
method: "invokedFromFile:lineNumber:",
args: [{
type: "NSString",
value: fileName
}, {
type: "NSInteger",
value: lineNumber
}]
};
}
/*Rotate the device to a given @c deviceOrientation. All device orientations except for
@c UIDeviceOrientationUnknown are supported. If a non-nil @c errorOrNil is provided, it will
be populated with the failure reason if the orientation change fails, otherwise a test failure
will be registered.
@param deviceOrientation The desired orientation of the device.
@param[out] errorOrNil Error that will be populated on failure. If @c nil, a test
failure will be reported if the rotation attempt fails.
@return @c YES if the rotation was successful, @c NO otherwise.*/
static rotateDeviceToOrientationErrorOrNil(element, deviceOrientation) {
if (!["landscape", "portrait"].some(option => option === deviceOrientation)) throw new Error("deviceOrientation should be one of [landscape, portrait], but got " + deviceOrientation);
return {
target: element,
method: "rotateDeviceToOrientation:errorOrNil:",
args: [{
type: "NSInteger",
value: sanitize_uiDeviceOrientation(deviceOrientation)
}]
};
}
/*Shakes the device. If a non-nil @c errorOrNil is provided, it will
be populated with the failure reason if the orientation change fails, otherwise a test failure
will be registered.
@param[out] errorOrNil Error that will be populated on failure. If @c nil, the a test
failure will be reported if the shake attempt fails.
@throws GREYFrameworkException if the action fails and @c errorOrNil is @c nil.
@return @c YES if the shake was successful, @c NO otherwise. If @c errorOrNil is @c nil and
the operation fails, it will throw an exception.*/
static shakeDeviceWithError(element) {
return {
target: element,
method: "shakeDeviceWithError:",
args: []
};
}
/*Dismisses the keyboard by resigning the first responder, if any. Will populate the provided
error if the first responder is not present or if the keyboard is not visible.
@param[out] errorOrNil Error that will be populated on failure. If @c nil, a test
failure will be reported if the dismissing fails.
@return @c YES if the dismissing of the keyboard was successful, @c NO otherwise.*/
static dismissKeyboardWithError(element) {
return {
target: element,
method: "dismissKeyboardWithError:",
args: []
};
}
}
module.exports = EarlGreyImpl;