Skip to content

Commit

Permalink
fix: premature resolution of wait conditions when using scopedBy
Browse files Browse the repository at this point in the history
When using a function style selector wait conditions fail early if the
scoped selector does not yield any results. Instead we should continue
to wait/check until the wait condition times out.

Additionally in order to retain custom friendly error messages that
include the selector that an exception occurred on we fallback to the
original wait behavior which includes the custom errors.
  • Loading branch information
Edward Pfremmer committed Jun 19, 2020
1 parent aaf5f29 commit 1bf8a3c
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 67 deletions.
20 changes: 20 additions & 0 deletions packages/page-objects/src/base-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class BaseElement extends BasePageObject {

async waitForInsert() {
await handleError.call(this, async () => {
if (typeof this._selector === 'function') {
try {
return await this._browser.waitUntil(async () => await this.isExisting());
} catch (e) {
// if the waitUntil condition fails fall through to the original non-scoped
// call so we continue to throw custom human readable faltest errors about the
// element selector that is missing
}
}

await this._browser.waitForInsert(this._selector);
}, async elementError => {
// If it's an expected error, that means a parent doesn't exist,
Expand All @@ -56,6 +66,16 @@ class BaseElement extends BasePageObject {

async waitForDestroy() {
await handleError.call(this, async () => {
if (typeof this._selector === 'function') {
try {
return await this._browser.waitUntil(async () => !(await this.isExisting()));
} catch (e) {
// if the waitUntil condition fails fall through to the original non-scoped
// call so we continue to throw custom human readable faltest errors about the
// element selector that was not destroyed
}
}

await this._browser.waitForDestroy(this._selector);
}, () => {
// If it's an expected error, that means a parent doesn't exist,
Expand Down
4 changes: 4 additions & 0 deletions packages/page-objects/src/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class Element extends BaseElement {
}

async waitForEnabled() {
await this.waitForInsert();
await this._browser.waitForEnabled(this._selector, ...arguments);
}

async waitForDisabled() {
await this.waitForInsert();
await this._browser.waitForDisabled(this._selector, ...arguments);
}

Expand All @@ -24,10 +26,12 @@ class Element extends BaseElement {
}

async waitForVisible() {
await this.waitForInsert();
await this._browser.waitForVisible(this._selector, ...arguments);
}

async waitForHidden() {
await this.waitForInsert();
await this._browser.waitForHidden(this._selector, ...arguments);
}

Expand Down
Loading

0 comments on commit 1bf8a3c

Please sign in to comment.