-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move manual calls on iOS to generated code
- Loading branch information
1 parent
a2bf0f0
commit b206d1a
Showing
15 changed files
with
478 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const {call} = require('./Invoke'); | ||
|
||
describe('call', () => { | ||
it('handles target as thunk', () => { | ||
expect(call(() => 'fn', 'method')()).toEqual({ | ||
target: { type: 'Invocation', value: 'fn' }, | ||
method: 'method', | ||
args: [] | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
This code is generated. | ||
For more information see generation/README.md. | ||
*/ | ||
|
||
|
||
|
||
class GREYCondition { | ||
/*Waits for the condition to be met until the specified @c seconds have elapsed. | ||
Will poll the condition as often as possible on the main thread while still giving a fair chance | ||
for other sources and handlers to be serviced. | ||
@remark Waiting on conditions with this method is very CPU intensive on the main thread. If | ||
you do not need to return immediately after the condition is met, the consider using | ||
GREYCondition::waitWithTimeout:pollInterval: | ||
@param seconds Amount of time to wait for the condition to be met, in seconds. | ||
@return @c YES if the condition was met before the timeout, @c NO otherwise. | ||
*/static waitWithTimeout(element, seconds) { | ||
if (typeof seconds !== "number") throw new Error("seconds should be a number, but got " + (seconds + (" (" + (typeof seconds + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: element | ||
}, | ||
method: "waitWithTimeout:", | ||
args: [{ | ||
type: "CGFloat", | ||
value: seconds | ||
}] | ||
}; | ||
} | ||
|
||
/*Waits for the condition to be met until the specified @c seconds have elapsed. Will poll the | ||
condition immediately and then no more than once every @c interval seconds. Will attempt to poll | ||
the condition as close as possible to every @c interval seconds. | ||
@remark Will allow the main thread to sleep instead of busily checking the condition. | ||
@param seconds Amount of time to wait for the condition to be met, in seconds. | ||
@param interval The minimum time that should elapse between checking the condition. | ||
@return @c YES if the condition was met before the timeout, @c NO otherwise. | ||
*/static waitWithTimeoutPollInterval(element, seconds, interval) { | ||
if (typeof seconds !== "number") throw new Error("seconds should be a number, but got " + (seconds + (" (" + (typeof seconds + ")")))); | ||
if (typeof interval !== "number") throw new Error("interval should be a number, but got " + (interval + (" (" + (typeof interval + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: element | ||
}, | ||
method: "waitWithTimeout:pollInterval:", | ||
args: [{ | ||
type: "CGFloat", | ||
value: seconds | ||
}, { | ||
type: "CGFloat", | ||
value: interval | ||
}] | ||
}; | ||
} | ||
|
||
} | ||
|
||
module.exports = GREYCondition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
This code is generated. | ||
For more information see generation/README.md. | ||
*/ | ||
|
||
|
||
function sanitize_greyElementInteraction(value) { | ||
return { | ||
type: "Invocation", | ||
value | ||
}; | ||
} | ||
class GREYCondition { | ||
static detoxConditionForElementMatched(interaction) { | ||
if (typeof interaction !== "object") { | ||
throw new Error('interaction should be a GREYElementInteraction, but got ' + JSON.stringify(interaction)); | ||
} | ||
|
||
return { | ||
target: { | ||
type: "Class", | ||
value: "GREYCondition" | ||
}, | ||
method: "detoxConditionForElementMatched:", | ||
args: [sanitize_greyElementInteraction(interaction)] | ||
}; | ||
} | ||
|
||
static detoxConditionForNotElementMatched(interaction) { | ||
if (typeof interaction !== "object") { | ||
throw new Error('interaction should be a GREYElementInteraction, but got ' + JSON.stringify(interaction)); | ||
} | ||
|
||
return { | ||
target: { | ||
type: "Class", | ||
value: "GREYCondition" | ||
}, | ||
method: "detoxConditionForNotElementMatched:", | ||
args: [sanitize_greyElementInteraction(interaction)] | ||
}; | ||
} | ||
|
||
} | ||
|
||
module.exports = GREYCondition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/** | ||
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: { | ||
type: "Class", | ||
value: element | ||
}, | ||
method: "inRoot:", | ||
args: [rootMatcher] | ||
}; | ||
} | ||
|
||
/*Performs the @c action repeatedly on the 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: { | ||
type: "Class", | ||
value: 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: { | ||
type: "Class", | ||
value: 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: { | ||
type: "Class", | ||
value: 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: { | ||
type: "Class", | ||
value: element | ||
}, | ||
method: "atIndex:", | ||
args: [{ | ||
type: "NSInteger", | ||
value: index | ||
}] | ||
}; | ||
} | ||
|
||
} | ||
|
||
module.exports = GREYInteraction; |
Oops, something went wrong.