From 635ac9e9be2d79f7d05216a73f84d9b600c80dff Mon Sep 17 00:00:00 2001 From: Doron Pearl Date: Mon, 31 Jul 2017 12:03:25 +0300 Subject: [PATCH 1/2] fix waitFor joint effort with @aarongreenwald --- detox/src/ios/expect.js | 2 ++ detox/test/e2e/e-waitfor.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/detox/src/ios/expect.js b/detox/src/ios/expect.js index 8fe9e8d8f8..ab755dae22 100644 --- a/detox/src/ios/expect.js +++ b/detox/src/ios/expect.js @@ -212,8 +212,10 @@ class WaitForInteraction extends Interaction { if (this._notCondition) { _conditionCall = invoke.call(invoke.IOS.Class('GREYCondition'), 'detoxConditionForNotElementMatched:', this._element._call); } + this._call = invoke.call(_conditionCall, 'waitWithTimeout:', invoke.IOS.CGFloat(timeout/1000)); await this.execute(); + await new MatcherAssertionInteraction(this._element, this._originalMatcher).execute(); } whileElement(searchMatcher) { return new WaitForActionInteraction(this._element, this._originalMatcher, searchMatcher); diff --git a/detox/test/e2e/e-waitfor.js b/detox/test/e2e/e-waitfor.js index 2900756fee..fabfa8ed88 100644 --- a/detox/test/e2e/e-waitfor.js +++ b/detox/test/e2e/e-waitfor.js @@ -1,3 +1,5 @@ +const sleep = async ms => new Promise(resolve => setTimeout(() => resolve(), ms)); + describe('WaitFor', () => { beforeEach(async() => { await device.reloadReactNative(); @@ -7,25 +9,30 @@ describe('WaitFor', () => { it('should wait until an element is created and exists in layout', async () => { await expect(element(by.id('createdAndVisibleText'))).toNotExist(); await waitFor(element(by.id('createdAndVisibleText'))).toExist().withTimeout(2000); - await expect(element(by.id('createdAndVisibleText'))).toExist(); + }); + + it('should fail the test when waiting for an element that does not exist', async () => { + const failTest = () => expect(element(by.id('does-not-exist'))).toExist(); + try { + await waitFor(element(by.id('does-not-exist'))).toExist().withTimeout(20); + failTest() + } catch (e) { + } }); it('should wait until an invisible element becomes visible', async() => { await expect(element(by.id('invisibleBecomingVisibleText'))).toBeNotVisible(); await waitFor(element(by.id('invisibleBecomingVisibleText'))).toBeVisible().withTimeout(2000); - await expect(element(by.id('invisibleBecomingVisibleText'))).toBeVisible(); }); it('should wait until an element is removed', async() => { await expect(element(by.id('deletedFromHierarchyText'))).toBeVisible(); await waitFor(element(by.id('deletedFromHierarchyText'))).toBeNotVisible().withTimeout(2000); - await expect(element(by.id('deletedFromHierarchyText'))).toBeNotVisible(); }); it('should find element by scrolling until it is visible', async() => { await expect(element(by.label('Text5'))).toBeNotVisible(); await waitFor(element(by.label('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down'); - await expect(element(by.label('Text5'))).toBeVisible(); }); }); From add2cdeff8a566cd443c90669aa3a98a4d148240 Mon Sep 17 00:00:00 2001 From: Doron Pearl Date: Mon, 31 Jul 2017 12:06:00 +0300 Subject: [PATCH 2/2] removed dead sleep code --- detox/test/e2e/e-waitfor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/detox/test/e2e/e-waitfor.js b/detox/test/e2e/e-waitfor.js index fabfa8ed88..d30ab274b7 100644 --- a/detox/test/e2e/e-waitfor.js +++ b/detox/test/e2e/e-waitfor.js @@ -1,4 +1,3 @@ -const sleep = async ms => new Promise(resolve => setTimeout(() => resolve(), ms)); describe('WaitFor', () => { beforeEach(async() => {