Skip to content

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

feat(rpc): misc fixes (#3351)

Dmitry Gozman83f56285493a
diff --git a/src/rpc/channels.ts b/src/rpc/channels.ts
index 2045ee3c92..80c63b12d8 100644
--- a/src/rpc/channels.ts
+++ b/src/rpc/channels.ts
@@ -1591,9 +1591,11 @@ export type WorkerInitializer = {
url: string,
};
export interface WorkerChannel extends Channel {
+ on(event: 'close', callback: (params: WorkerCloseEvent) => void): this;
evaluateExpression(params: WorkerEvaluateExpressionParams): Promise<WorkerEvaluateExpressionResult>;
evaluateExpressionHandle(params: WorkerEvaluateExpressionHandleParams): Promise<WorkerEvaluateExpressionHandleResult>;
}
+export type WorkerCloseEvent = {};
export type WorkerEvaluateExpressionParams = {
expression: string,
isFunction: boolean,
diff --git a/src/rpc/client/browserServer.ts b/src/rpc/client/browserServer.ts
index 79b730ec55..bf917c75bd 100644
--- a/src/rpc/client/browserServer.ts
+++ b/src/rpc/client/browserServer.ts
@@ -50,6 +50,4 @@ export class BrowserServer extends ChannelOwner<BrowserServerChannel, BrowserSer
await this._channel.close();
});
}
-
- _checkLeaks() {}
}
diff --git a/src/rpc/protocol.yml b/src/rpc/protocol.yml
index d837e088ba..7f68198a86 100644
--- a/src/rpc/protocol.yml
+++ b/src/rpc/protocol.yml
@@ -1343,6 +1343,9 @@ Worker:
returns:
handle: JSHandle
+ events:
+
+ close:
JSHandle:
diff --git a/test/browsertype-connect.spec.ts b/test/browsertype-connect.spec.ts
index cb378d7e6a..0d6cb2057c 100644
--- a/test/browsertype-connect.spec.ts
+++ b/test/browsertype-connect.spec.ts
@@ -18,7 +18,7 @@
import utils from './utils';
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
-it.slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {
+it.slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
{
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@@ -34,26 +34,29 @@ it.slow()('should be able to reconnect to a browser', async({browserType, defaul
await page.goto(server.EMPTY_PAGE);
await browser.close();
}
- await (browserServer as any)._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
-it.fail(USES_HOOKS || (CHROMIUM && WIN)).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions, server}) => {
+it.fail(USES_HOOKS || (CHROMIUM && WIN)).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') };
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e);
- await (browserServer as any)._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
expect(error.message).toContain('Dummy');
});
-it('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => {
+it('should set the browser connected state', async ({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(remote.isConnected()).toBe(true);
await remote.close();
expect(remote.isConnected()).toBe(false);
- await (browserServer as any)._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
diff --git a/test/browsertype-launch-server.spec.js b/test/browsertype-launch-server.spec.js
index cc30fb15ab..4f6b0fde46 100644
--- a/test/browsertype-launch-server.spec.js
+++ b/test/browsertype-launch-server.spec.js
@@ -20,7 +20,7 @@ const fs = require('fs');
const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
-it('should work', async({browserType, defaultBrowserOptions}) => {
+it('should work', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browserContext = await browser.newContext();
@@ -30,7 +30,8 @@ it('should work', async({browserType, defaultBrowserOptions}) => {
expect(await page.evaluate('11 * 11')).toBe(121);
await page.close();
await browser.close();
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
@@ -76,7 +77,7 @@ it('should fire close event', async ({browserType, defaultBrowserOptions}) => {
expect(result.signal).toBe(null);
});
-it('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => {
+it('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server, toImpl}) => {
server.setRoute('/one-style.css', () => {});
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@@ -86,11 +87,12 @@ it('should reject navigation when browser closes', async({browserType, defaultBr
await remote.close();
const error = await navigationPromise;
expect(error.message).toContain('Navigation failed because page was closed!');
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
-it('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => {
+it('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server, toImpl}) => {
server.setRoute('/empty.html', () => {});
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@@ -103,18 +105,20 @@ it('should reject waitForSelector when browser closes', async({browserType, defa
await remote.close();
const error = await watchdog;
expect(error.message).toContain('Protocol error');
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
-it('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => {
+it('should throw if used after disconnect', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const page = await remote.newPage();
await remote.close();
const error = await page.evaluate('1 + 1').catch(e => e);
expect(error.message).toContain('has been closed');
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
diff --git a/test/multiclient.spec.js b/test/multiclient.spec.js
index d30e32479e..1f378527d8 100644
--- a/test/multiclient.spec.js
+++ b/test/multiclient.spec.js
@@ -17,7 +17,7 @@
const {FFOX, CHROMIUM, WEBKIT} = testOptions;
-it('should work across sessions', async ({browserType, defaultBrowserOptions}) => {
+it('should work across sessions', async ({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(browser1.contexts().length).toBe(0);
@@ -34,7 +34,8 @@ it('should work across sessions', async ({browserType, defaultBrowserOptions}) =
await browser1.close();
await browser2.close();
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
@@ -72,7 +73,7 @@ it.slow()('should be emitted when: browser gets closed, disconnected or underlyi
expect(disconnectedRemote2).toBe(1);
});
-it('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions}) => {
+it('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browser2 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@@ -83,11 +84,12 @@ it('should be able to connect multiple times to the same browser', async({browse
const page2 = await browser2.newPage();
expect(await page2.evaluate(() => 7 * 6)).toBe(42, 'original browser should still work');
await browser2.close();
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});
-it('should not be able to close remote browser', async({browserType, defaultBrowserOptions}) => {
+it('should not be able to close remote browser', async({browserType, defaultBrowserOptions, toImpl}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
{
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@@ -99,6 +101,7 @@ it('should not be able to close remote browser', async({browserType, defaultBrow
await remote.newContext();
await remote.close();
}
- await browserServer._checkLeaks();
+ if (toImpl)
+ await toImpl(browserServer)._checkLeaks();
await browserServer.close();
});