Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: do not wait for navigations while evaluating injected source (#1347)

Dmitry Gozman7c59f9ca9a45
diff --git a/src/dom.ts b/src/dom.ts
index 58d52b4e32..92f0e318da 100644
--- a/src/dom.ts
+++ b/src/dom.ts
@@ -45,7 +45,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
this.frame = frame;
}
- async _evaluate(returnByValue: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
+ async _evaluate(returnByValue: boolean, waitForNavigations: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
const needsAdoption = (value: any): boolean => {
return typeof value === 'object' && value instanceof ElementHandle && value._context !== this;
};
@@ -54,7 +54,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
// Only go through asynchronous calls if required.
return await this.frame._page._frameManager.waitForNavigationsCreatedBy(async () => {
return this._delegate.evaluate(this, returnByValue, pageFunction, ...args);
- });
+ }, waitForNavigations ? undefined : { waitUntil: 'nowait' });
}
const toDispose: Promise<ElementHandle>[] = [];
@@ -69,7 +69,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
try {
result = await this.frame._page._frameManager.waitForNavigationsCreatedBy(async () => {
return this._delegate.evaluate(this, returnByValue, pageFunction, ...adopted);
- });
+ }, waitForNavigations ? undefined : { waitUntil: 'nowait' });
} finally {
toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose()));
}
@@ -97,7 +97,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
${custom.join(',\n')}
])
`;
- this._injectedPromise = this.evaluateHandle(source);
+ this._injectedPromise = this._evaluate(false /* returnByValue */, false /* waitForNavigations */, source);
this._injectedGeneration = selectors._generation;
}
return this._injectedPromise;
diff --git a/src/javascript.ts b/src/javascript.ts
index 73add31a0b..fdb7fb60ee 100644
--- a/src/javascript.ts
+++ b/src/javascript.ts
@@ -32,16 +32,16 @@ export class ExecutionContext {
this._delegate = delegate;
}
- _evaluate(returnByValue: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
+ _evaluate(returnByValue: boolean, waitForNavigations: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
return this._delegate.evaluate(this, returnByValue, pageFunction, ...args);
}
evaluate: types.Evaluate = async (pageFunction, ...args) => {
- return this._evaluate(true /* returnByValue */, pageFunction, ...args);
+ return this._evaluate(true /* returnByValue */, true /* waitForNavigations */, pageFunction, ...args);
}
evaluateHandle: types.EvaluateHandle = async (pageFunction, ...args) => {
- return this._evaluate(false /* returnByValue */, pageFunction, ...args);
+ return this._evaluate(false /* returnByValue */, true /* waitForNavigations */, pageFunction, ...args);
}
_createHandle(remoteObject: any): JSHandle {
diff --git a/test/evaluation.spec.js b/test/evaluation.spec.js
index 8dc1e25cc1..53414b1f96 100644
--- a/test/evaluation.spec.js
+++ b/test/evaluation.spec.js
@@ -230,8 +230,9 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT,
await page.evaluate(e => e.textContent, element).catch(e => error = e);
expect(error.message).toContain('JSHandle is disposed');
});
- // flaky: https://github.com/microsoft/playwright/pull/1277/checks?check_run_id=496501774
- it.fail(FFOX && LINUX)('should simulate a user gesture', async({page, server}) => {
+ it.fail(FFOX)('should simulate a user gesture', async({page, server}) => {
+ // flaky linux: https://github.com/microsoft/playwright/pull/1277/checks?check_run_id=496501774
+ // flaky win: https://github.com/microsoft/playwright/pull/1323/checks?check_run_id=501701278
const result = await page.evaluate(() => {
document.body.appendChild(document.createTextNode('test'));
document.execCommand('selectAll');