From 34e86991853c0e979354fb59dbe37af85b4f7abb Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Sun, 11 Jun 2017 15:39:52 +0300 Subject: [PATCH 1/3] Added optipnal percentage parameter to swipe action --- detox/src/ios/expect.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/detox/src/ios/expect.js b/detox/src/ios/expect.js index a6b4064a5f..a006378966 100644 --- a/detox/src/ios/expect.js +++ b/detox/src/ios/expect.js @@ -119,7 +119,7 @@ class ScrollEdgeAction extends Action { } class SwipeAction extends Action { - constructor(direction, speed) { + constructor(direction, speed, percentage) { super(); if (typeof direction !== 'string') throw new Error(`SwipeAction ctor 1st argument must be a string, got ${typeof direction}`); if (typeof speed !== 'string') throw new Error(`SwipeAction ctor 2nd argument must be a string, got ${typeof speed}`); @@ -130,12 +130,29 @@ class SwipeAction extends Action { case 'down': direction = 4; break; default: throw new Error(`SwipeAction direction must be a 'left'/'right'/'up'/'down', got ${direction}`); } - if (speed == 'fast') { - this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForSwipeFastInDirection:', invoke.IOS.NSInteger(direction)); - } else if (speed == 'slow') { - this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForSwipeSlowInDirection:', invoke.IOS.NSInteger(direction)); + if (percentage) { + let x, y; + switch (direction) { + case 1: x = percentage, y = 0.0; break; + case 2: x = percentage, y = 0.0; break; + case 3: y = percentage, x = 0.0; break; + case 4: y = percentage, x = 0.0; break; + } + if (speed == 'fast') { + this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForSwipeFastInDirection:xOriginStartPercentage:yOriginStartPercentage:', invoke.IOS.NSInteger(direction), invoke.IOS.CGFloat(x), invoke.IOS.CGFloat(y)); + } else if (speed == 'slow') { + this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForSwipeSlowInDirection:xOriginStartPercentage:yOriginStartPercentage:', invoke.IOS.NSInteger(direction), invoke.IOS.CGFloat(x), invoke.IOS.CGFloat(y)); + } else { + throw new Error(`SwipeAction speed must be a 'fast'/'slow', got ${speed}`); + } } else { - throw new Error(`SwipeAction speed must be a 'fast'/'slow', got ${speed}`); + if (speed == 'fast') { + this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForSwipeFastInDirection:', invoke.IOS.NSInteger(direction)); + } else if (speed == 'slow') { + this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForSwipeSlowInDirection:', invoke.IOS.NSInteger(direction)); + } else { + throw new Error(`SwipeAction speed must be a 'fast'/'slow', got ${speed}`); + } } } } @@ -262,10 +279,10 @@ class Element { this._selectElementWithMatcher(this._originalMatcher._extendToDescendantScrollViews()); return await new ActionInteraction(this, new ScrollEdgeAction(edge)).execute(); } - async swipe(direction, speed = 'fast') { + async swipe(direction, speed = 'fast', percentage = 0) { // override the user's element selection with an extended matcher that avoids RN issues with RCTScrollView this._selectElementWithMatcher(this._originalMatcher._avoidProblematicReactNativeElements()); - return await new ActionInteraction(this, new SwipeAction(direction, speed)).execute(); + return await new ActionInteraction(this, new SwipeAction(direction, speed, percentage)).execute(); } } From 0d56e2650d9d8965761076e2a2a11f2b43cf2891 Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Sun, 11 Jun 2017 15:57:23 +0300 Subject: [PATCH 2/3] API tests for swipe action with percentage --- detox/src/ios/expect.test.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/detox/src/ios/expect.test.js b/detox/src/ios/expect.test.js index 764a4c136d..2a96b54023 100644 --- a/detox/src/ios/expect.test.js +++ b/detox/src/ios/expect.test.js @@ -111,10 +111,14 @@ describe('expect', async () => { await e.element(e.by.id('ScrollView161')).scrollTo('left'); await e.element(e.by.id('ScrollView161')).scrollTo('right'); await e.element(e.by.id('ScrollView799')).swipe('down'); - await e.element(e.by.id('ScrollView799')).swipe('down', 'fast'); - await e.element(e.by.id('ScrollView799')).swipe('up', 'slow'); - await e.element(e.by.id('ScrollView799')).swipe('left', 'fast'); - await e.element(e.by.id('ScrollView799')).swipe('right', 'slow'); +await e.element(e.by.id('ScrollView799')).swipe('down', 'fast'); +await e.element(e.by.id('ScrollView799')).swipe('up', 'slow'); +await e.element(e.by.id('ScrollView799')).swipe('left', 'fast'); +await e.element(e.by.id('ScrollView799')).swipe('right', 'slow'); +await e.element(e.by.id('ScrollView799')).swipe('down', 'fast', 0.9); +await e.element(e.by.id('ScrollView799')).swipe('up', 'slow', 0.9); +await e.element(e.by.id('ScrollView799')).swipe('left', 'fast', 0.9); +await e.element(e.by.id('ScrollView799')).swipe('right', 'slow', 0.9); await e.element(e.by.id('ScrollView799')).atIndex(1); }); @@ -130,7 +134,8 @@ describe('expect', async () => { await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe(4, 'fast')); await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('noDirection', 0)); await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('noDirection', 'fast')); - await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow')); +await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow')); +await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow', 0.9)); await expectToThrow(() => e.element(e.by.id('ScrollView799')).atIndex('NaN')); }); From 34e622a01045df391bbdeff0e5680fcfc24480c1 Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Sun, 11 Jun 2017 16:13:37 +0300 Subject: [PATCH 3/3] fix alignment --- detox/src/ios/expect.test.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/detox/src/ios/expect.test.js b/detox/src/ios/expect.test.js index 2a96b54023..1b86c1901d 100644 --- a/detox/src/ios/expect.test.js +++ b/detox/src/ios/expect.test.js @@ -111,14 +111,14 @@ describe('expect', async () => { await e.element(e.by.id('ScrollView161')).scrollTo('left'); await e.element(e.by.id('ScrollView161')).scrollTo('right'); await e.element(e.by.id('ScrollView799')).swipe('down'); -await e.element(e.by.id('ScrollView799')).swipe('down', 'fast'); -await e.element(e.by.id('ScrollView799')).swipe('up', 'slow'); -await e.element(e.by.id('ScrollView799')).swipe('left', 'fast'); -await e.element(e.by.id('ScrollView799')).swipe('right', 'slow'); -await e.element(e.by.id('ScrollView799')).swipe('down', 'fast', 0.9); -await e.element(e.by.id('ScrollView799')).swipe('up', 'slow', 0.9); -await e.element(e.by.id('ScrollView799')).swipe('left', 'fast', 0.9); -await e.element(e.by.id('ScrollView799')).swipe('right', 'slow', 0.9); + await e.element(e.by.id('ScrollView799')).swipe('down', 'fast'); + await e.element(e.by.id('ScrollView799')).swipe('up', 'slow'); + await e.element(e.by.id('ScrollView799')).swipe('left', 'fast'); + await e.element(e.by.id('ScrollView799')).swipe('right', 'slow'); + await e.element(e.by.id('ScrollView799')).swipe('down', 'fast', 0.9); + await e.element(e.by.id('ScrollView799')).swipe('up', 'slow', 0.9); + await e.element(e.by.id('ScrollView799')).swipe('left', 'fast', 0.9); + await e.element(e.by.id('ScrollView799')).swipe('right', 'slow', 0.9); await e.element(e.by.id('ScrollView799')).atIndex(1); }); @@ -134,8 +134,8 @@ await e.element(e.by.id('ScrollView799')).swipe('right', 'slow', 0.9); await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe(4, 'fast')); await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('noDirection', 0)); await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('noDirection', 'fast')); -await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow')); -await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow', 0.9)); + await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow')); + await expectToThrow(() => e.element(e.by.id('ScrollView799')).swipe('down', 'NotFastNorSlow', 0.9)); await expectToThrow(() => e.element(e.by.id('ScrollView799')).atIndex('NaN')); });