Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for tapAtPoint action #189

Merged
merged 4 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions detox/ios/Detox/MethodInvocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ + (id) getValue:(id)value withType:(id)type onError:(void (^)(NSString*))onError
CGFloat v = [value doubleValue];
return [NSNumber numberWithDouble:v];
}
if ([type isEqualToString:@"CGPoint"])
{
if (![value isKindOfClass:[NSDictionary class]]) return nil;
NSDictionary *v = (NSDictionary*)value;
CGFloat x = [[v objectForKey:@"x"] floatValue];
CGFloat y = [[v objectForKey:@"y"] floatValue];
return [NSValue valueWithCGPoint:CGPointMake(x, y)];
}
if ([type isEqualToString:@"CGRect"])
{
if (![value isKindOfClass:[NSDictionary class]]) return nil;
Expand Down
10 changes: 10 additions & 0 deletions detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class TapAction extends Action {
}
}

class TapAtPointAction extends Action {
constructor(value) {
super();
this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForTapAtPoint:', invoke.IOS.CGPoint(value));
}
}

class LongPressAction extends Action {
constructor() {
super();
Expand Down Expand Up @@ -254,6 +261,9 @@ class Element {
async tap() {
return await new ActionInteraction(this, new TapAction()).execute();
}
async tapAtPoint(value) {
return await new ActionInteraction(this, new TapAtPointAction(value)).execute();
}
async longPress() {
return await new ActionInteraction(this, new LongPressAction()).execute();
}
Expand Down
1 change: 1 addition & 0 deletions detox/src/ios/expect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('expect', async () => {

it(`interactions`, async () => {
await e.element(e.by.label('Tap Me')).tap();
await e.element(e.by.label('Tap Me')).tapAtPoint({x: 10, y:10});
await e.element(e.by.label('Tap Me')).longPress();
await e.element(e.by.id('UniqueId819')).multiTap(3);
await e.element(e.by.id('UniqueId937')).typeText('passcode');
Expand Down
5 changes: 5 additions & 0 deletions detox/test/e2e/c-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe('Actions', () => {
await expect(element(by.id('UniqueId819'))).toHaveLabel('Taps: 3');
});

it('should tap on an element at point', async () => {
await element(by.id('View7990')).tapAtPoint({x:180, y:140});
await expect(element(by.id('UniqueId819'))).toHaveLabel('Taps: 1');
});

// Backspace is supported by using "\b" in the string. Return key is supported with "\n"
it('should type in an element', async () => {
await element(by.id('UniqueId937')).tap();
Expand Down
2 changes: 1 addition & 1 deletion detox/test/src/Screens/ActionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class ActionsScreen extends Component {
render() {
if (this.state.greeting) return this.renderAfterButton();
return (
<View style={{ flex: 1, paddingTop: 40, justifyContent: 'flex-start' }}>
<View testID='View7990' style={{ flex: 1, paddingTop: 40, justifyContent: 'flex-start' }}>

<TouchableOpacity onPress={this.onButtonPress.bind(this, 'Tap Working')}
onLongPress={this.onButtonPress.bind(this, 'Long Press Working')}
Expand Down
8 changes: 8 additions & 0 deletions docs/APIRef.ActionsOnElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Actions are functions that emulate user behavior. They are being performed on ma
- [`.tap()`](#tap)
- [`.longPress()`](#longpress)
- [`.multiTap()`](#multitaptimes)
- [`.tapAtPoint()`](#tapatpoint)
- [`.typeText()`](#typetexttext)
- [`.replaceText()`](#replacetexttext)
- [`.clearText()`](#cleartext)
Expand Down Expand Up @@ -39,6 +40,13 @@ Simulate multiple taps on an element.
```js
await element(by.id('tappable')).multiTap(3);
```
### `tapAtPoint()`
Simulate tap at a specific point on an element.<br><br>
Note: The point coordinates are relative to the matched element and the element size could changes on different devices or even when changing the device font size.

```js
await element(by.id('tappable')).tapAtPoint({x:5, y:10});
```

### `typeText(text)`
Use the builtin keyboard to type text into a text field.
Expand Down