Skip to content

Commit

Permalink
Merge branch 'main' into waitForSelector-fixContext
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Dec 15, 2021
2 parents c01cdac + 1c44551 commit 5ae5376
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/common/DOMWorld.ts
Expand Up @@ -645,6 +645,7 @@ export class DOMWorld {
const waitTaskOptions: WaitTaskOptions = {
domWorld: this,
predicateBody: helper.makePredicateString(predicate, queryOne),
predicateAcceptsContextElement: true,
title,
polling,
timeout,
Expand Down Expand Up @@ -691,6 +692,7 @@ export class DOMWorld {
const waitTaskOptions: WaitTaskOptions = {
domWorld: this,
predicateBody: helper.makePredicateString(predicate),
predicateAcceptsContextElement: true,
title,
polling,
timeout,
Expand All @@ -717,6 +719,7 @@ export class DOMWorld {
const waitTaskOptions: WaitTaskOptions = {
domWorld: this,
predicateBody: pageFunction,
predicateAcceptsContextElement: false,
title: 'function',
polling,
timeout,
Expand All @@ -737,6 +740,7 @@ export class DOMWorld {
export interface WaitTaskOptions {
domWorld: DOMWorld;
predicateBody: Function | string;
predicateAcceptsContextElement: boolean;
title: string;
polling: string | number;
timeout: number;
Expand All @@ -753,6 +757,7 @@ export class WaitTask {
_polling: string | number;
_timeout: number;
_predicateBody: string;
_predicateAcceptsContextElement: boolean;
_args: SerializableOrJSHandle[];
_binding: PageBinding;
_runCount = 0;
Expand Down Expand Up @@ -786,6 +791,8 @@ export class WaitTask {
this._timeout = options.timeout;
this._root = options.root;
this._predicateBody = getPredicateBody(options.predicateBody);
this._predicateAcceptsContextElement =
options.predicateAcceptsContextElement;
this._args = options.args;
this._binding = options.binding;
this._runCount = 0;
Expand Down Expand Up @@ -836,6 +843,7 @@ export class WaitTask {
waitForPredicatePageFunction,
this._root,
this._predicateBody,
this._predicateAcceptsContextElement,
this._polling,
this._timeout,
...this._args
Expand All @@ -845,6 +853,7 @@ export class WaitTask {
waitForPredicatePageFunction,
null,
this._predicateBody,
this._predicateAcceptsContextElement,
this._polling,
this._timeout,
...this._args
Expand Down Expand Up @@ -912,6 +921,7 @@ export class WaitTask {
async function waitForPredicatePageFunction(
root: Element | Document | null,
predicateBody: string,
predicateAcceptsContextElement: boolean,
polling: string,
timeout: number,
...args: unknown[]
Expand All @@ -928,7 +938,9 @@ async function waitForPredicatePageFunction(
* @returns {!Promise<*>}
*/
async function pollMutation(): Promise<unknown> {
const success = await predicate(root, ...args);
const success = predicateAcceptsContextElement
? await predicate(root, ...args)
: await predicate(...args);
if (success) return Promise.resolve(success);

let fulfill;
Expand All @@ -938,7 +950,9 @@ async function waitForPredicatePageFunction(
observer.disconnect();
fulfill();
}
const success = await predicate(root, ...args);
const success = predicateAcceptsContextElement
? await predicate(root, ...args)
: await predicate(...args);
if (success) {
observer.disconnect();
fulfill(success);
Expand All @@ -963,7 +977,9 @@ async function waitForPredicatePageFunction(
fulfill();
return;
}
const success = await predicate(root, ...args);
const success = predicateAcceptsContextElement
? await predicate(root, ...args)
: await predicate(...args);
if (success) fulfill(success);
else requestAnimationFrame(onRaf);
}
Expand All @@ -980,7 +996,9 @@ async function waitForPredicatePageFunction(
fulfill();
return;
}
const success = await predicate(root, ...args);
const success = predicateAcceptsContextElement
? await predicate(root, ...args)
: await predicate(...args);
if (success) fulfill(success);
else setTimeout(onTimeout, pollInterval);
}
Expand Down
2 changes: 1 addition & 1 deletion test/network.spec.ts
Expand Up @@ -592,7 +592,7 @@ describe('network', function () {
expect(requests.get('script.js').isNavigationRequest()).toBe(false);
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
});
it('should work when navigating to image', async () => {
itFailsFirefox('should work when navigating to image', async () => {
const { page, server } = getTestState();

const requests = [];
Expand Down
6 changes: 5 additions & 1 deletion test/waittask.spec.ts
Expand Up @@ -293,7 +293,11 @@ describe('waittask specs', function () {
const div = await page.$('div');
let resolved = false;
const waitForFunction = page
.waitForFunction((element) => !element.parentElement, {}, div)
.waitForFunction(
(element) => element.localName === 'div' && !element.parentElement,
{},
div
)
.then(() => (resolved = true));
expect(resolved).toBe(false);
await page.evaluate((element: HTMLElement) => element.remove(), div);
Expand Down

0 comments on commit 5ae5376

Please sign in to comment.