Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix waitFor #218

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe waitFor...whileElement doesn't fail as well, it needs to be consistent with waitFor...withTimeout

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, not conditions are not handled properly. We'll need to fix them as well.

return new WaitForActionInteraction(this._element, this._originalMatcher, searchMatcher);
Expand Down
14 changes: 10 additions & 4 deletions detox/test/e2e/e-waitfor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

describe('WaitFor', () => {
beforeEach(async() => {
await device.reloadReactNative();
Expand All @@ -7,25 +8,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();
});

});