Skip to content

Commit

Permalink
Move manual calls on iOS to generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Feb 10, 2018
1 parent a2bf0f0 commit b206d1a
Show file tree
Hide file tree
Showing 15 changed files with 478 additions and 46 deletions.
11 changes: 11 additions & 0 deletions detox/src/invoke/Invoke.test.js
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: []
})
});
});
48 changes: 48 additions & 0 deletions detox/src/ios/earlgreyapi/GREYActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,54 @@ simulate a long press.
};
}

/*Returns an action that holds down finger for specified @c duration to simulate a long press.
@param duration The duration of the long press.
@return A GREYAction that performs a long press on an element.
*/static actionForLongPressWithDuration(duration) {
if (typeof duration !== "number") throw new Error("duration should be a number, but got " + (duration + (" (" + (typeof duration + ")"))));
return {
target: {
type: "Class",
value: "GREYActions"
},
method: "actionForLongPressWithDuration:",
args: [{
type: "CGFloat",
value: duration
}]
};
}

/*Returns an action that holds down finger for specified @c duration at the specified @c point
(interpreted as being relative to the element) to simulate a long press.
@param point The point that should be tapped.
@param duration The duration of the long press.
@return A GREYAction that performs a long press on an element.
*/static actionForLongPressAtPointDuration(point, duration) {
if (typeof point !== "object") throw new Error("point should be a object, but got " + (point + (" (" + (typeof point + ")"))));
if (typeof point.x !== "number") throw new Error("point.x should be a number, but got " + (point.x + (" (" + (typeof point.x + ")"))));
if (typeof point.y !== "number") throw new Error("point.y should be a number, but got " + (point.y + (" (" + (typeof point.y + ")"))));
if (typeof duration !== "number") throw new Error("duration should be a number, but got " + (duration + (" (" + (typeof duration + ")"))));
return {
target: {
type: "Class",
value: "GREYActions"
},
method: "actionForLongPressAtPoint:duration:",
args: [{
type: "CGPoint",
value: point
}, {
type: "CGFloat",
value: duration
}]
};
}

/*Returns an action that scrolls a @c UIScrollView by @c amount (in points) in the specified
@c direction.
Expand Down
68 changes: 68 additions & 0 deletions detox/src/ios/earlgreyapi/GREYCondition.js
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;
47 changes: 47 additions & 0 deletions detox/src/ios/earlgreyapi/GREYConditionDetox.js
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;
146 changes: 146 additions & 0 deletions detox/src/ios/earlgreyapi/GREYInteraction.js
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;
Loading

0 comments on commit b206d1a

Please sign in to comment.