Skip to content

Commit

Permalink
fix(playwright): some wait funcs draw error due to switchTo iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Oct 9, 2023
1 parent ed5d43c commit 1f4f8f3
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,18 @@ class Playwright extends Helper {
const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
locator = new Locator(locator, 'css');
const context = await this._getContext();
const waiter = context.waitForSelector(buildLocatorString(locator), { timeout: waitTimeout, state: 'visible' });
let waiter;

// we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
if (this.frame) {
const { setTimeout } = require('timers/promises');
await setTimeout(waitTimeout);
waiter = await this.frame.locator(buildLocatorString(locator)).first().isVisible();
if (!waiter) throw new Error(`element (${locator.toString()}) still not visible after ${waitTimeout / 1000} sec.`);
return;
}

waiter = context.waitForSelector(buildLocatorString(locator), { timeout: waitTimeout, state: 'visible' });
return waiter.catch((err) => {
throw new Error(`element (${locator.toString()}) still not visible after ${waitTimeout / 1000} sec\n${err.message}`);
});
Expand All @@ -2393,7 +2404,18 @@ class Playwright extends Helper {
const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
locator = new Locator(locator, 'css');
const context = await this._getContext();
const waiter = context.waitForSelector(buildLocatorString(locator), { timeout: waitTimeout, state: 'hidden' });
let waiter;

// we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
if (this.frame) {
const { setTimeout } = require('timers/promises');
await setTimeout(waitTimeout);
waiter = await this.frame.locator(buildLocatorString(locator)).first().isHidden();
if (!waiter) throw new Error(`element (${locator.toString()}) still visible after ${waitTimeout / 1000} sec.`);
return;
}

waiter = context.waitForSelector(buildLocatorString(locator), { timeout: waitTimeout, state: 'hidden' });
return waiter.catch((err) => {
throw new Error(`element (${locator.toString()}) still visible after ${waitTimeout / 1000} sec\n${err.message}`);
});
Expand All @@ -2406,6 +2428,18 @@ class Playwright extends Helper {
const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
locator = new Locator(locator, 'css');
const context = await this._getContext();

let waiter;

// we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
if (this.frame) {
const { setTimeout } = require('timers/promises');
await setTimeout(waitTimeout);
waiter = await this.frame.locator(buildLocatorString(locator)).first().isHidden();
if (!waiter) throw new Error(`element (${locator.toString()}) still not hidden after ${waitTimeout / 1000} sec.`);
return;
}

return context.waitForSelector(buildLocatorString(locator), { timeout: waitTimeout, state: 'hidden' }).catch((err) => {
throw new Error(`element (${locator.toString()}) still not hidden after ${waitTimeout / 1000} sec\n${err.message}`);
});
Expand Down

0 comments on commit 1f4f8f3

Please sign in to comment.