forked from wix/Detox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGREYInteraction.js
131 lines (104 loc) · 5.42 KB
/
GREYInteraction.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
This code is generated.
For more information see generation/README.md.
*/
class GREYInteraction {
/*Indicates that the current interaction should be performed on a UI element contained inside
another UI element that is uniquely matched by @c rootMatcher.
@param rootMatcher Matcher used to select the container of the element the interaction
will be performed on.
@return The provided GREYInteraction instance, with an appropriate rootMatcher.*/
static inRoot(element, rootMatcher) {
if (typeof rootMatcher !== "object" || rootMatcher.type !== "Invocation" || typeof rootMatcher.value !== "object" || typeof rootMatcher.value.target !== "object" || rootMatcher.value.target.value !== "GREYMatchers") {
throw new Error('rootMatcher should be a GREYMatcher, but got ' + JSON.stringify(rootMatcher));
}
return {
target: element,
method: "inRoot:",
args: [rootMatcher]
};
}
/*Performs the @c action repeatedly on the element matching the @c matcher until the element
to interact with (specified by GREYInteraction::selectElementWithMatcher:) is found or a
timeout occurs. The search action is only performed when coupled with
GREYInteraction::performAction:, GREYInteraction::assert:, or
GREYInteraction::assertWithMatcher: APIs. This API only creates an interaction consisting of
repeated executions of the search action provided. You need to call an action or assertion
after this in order to interaction with the element being searched for.
For example, this code will perform an upward scroll of 50 points until an element is found
and then tap on it:
@code
[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"elementToFind")]
usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, 50.0f)
onElementWithMatcher:grey_accessibilityID(@"ScrollingWindow")]
performAction:grey_tap()] // This should be separately called for the action.
@endcode
@param action The action to be performed on the element.
@param matcher The matcher that the element matches.
@return The provided GREYInteraction instance, with an appropriate action and matcher.*/
static usingSearchActionOnElementWithMatcher(element, action, matcher) {
if (typeof action !== "object" || action.type !== "Invocation" || typeof action.value !== "object" || typeof action.value.target !== "object" || action.value.target.value !== "GREYActions") {
throw new Error('action should be a GREYAction, but got ' + JSON.stringify(action));
}
if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") {
throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher));
}
return {
target: element,
method: "usingSearchAction:onElementWithMatcher:",
args: [action, matcher]
};
}
/*Performs an @c action on the selected UI element.
@param action The action to be performed on the @c element.
@throws NSException if the action fails.
@return The provided GREYInteraction instance with an appropriate action.*/
static performAction(element, action) {
if (typeof action !== "object" || action.type !== "Invocation" || typeof action.value !== "object" || typeof action.value.target !== "object" || action.value.target.value !== "GREYActions") {
throw new Error('action should be a GREYAction, but got ' + JSON.stringify(action));
}
return {
target: element,
method: "performAction:",
args: [action]
};
}
/*Performs an assertion that evaluates @c matcher on the selected UI element.
@param matcher The matcher to be evaluated on the @c element.
@return The provided GREYInteraction instance with a matcher to be evaluated on an element.*/
static assertWithMatcher(element, matcher) {
if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") {
throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher));
}
return {
target: element,
method: "assertWithMatcher:",
args: [matcher]
};
}
/*In case of multiple matches, selects the element at the specified index. In case of the
index being over the number of matched elements, it throws an exception. Please make sure
that this is used after you've created the matcher. For example, in case three elements are
matched, and you wish to match with the second one, then @c atIndex would be used in this
manner:
@code
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Generic Matcher")] atIndex:1];
@endcode
@param index The zero-indexed position of the element in the list of matched elements
to be selected.
@throws NSException if the @c index is more than the number of matched elements.
@return An interaction (assertion or an action) to be performed on the element at the
specified index in the list of matched elements.*/
static atIndex(element, index) {
if (typeof index !== "number") throw new Error("index should be a number, but got " + (index + (" (" + (typeof index + ")"))));
return {
target: element,
method: "atIndex:",
args: [{
type: "NSInteger",
value: index
}]
};
}
}
module.exports = GREYInteraction;