Skip to content

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

chore: PlaywrightClient/Server enhancements (#7980)

Max Schmitt869f8d541b60
diff --git a/src/remote/playwrightClient.ts b/src/remote/playwrightClient.ts
index dbca997b41..535c46e16e 100644
--- a/src/remote/playwrightClient.ts
+++ b/src/remote/playwrightClient.ts
@@ -49,7 +49,7 @@ export class PlaywrightClient {
playwrightClientPromise,
errorPromise,
closePromise,
- new Promise((_, reject) => timer = setTimeout(reject, timeout))
+ new Promise((_, reject) => timer = setTimeout(() => reject(`Timeout of ${timeout}ms exceeded while connecting.`), timeout))
]);
return await playwrightClientPromise;
} finally {
diff --git a/src/remote/playwrightServer.ts b/src/remote/playwrightServer.ts
index 529f5b65f5..386634bc43 100644
--- a/src/remote/playwrightServer.ts
+++ b/src/remote/playwrightServer.ts
@@ -33,6 +33,7 @@ export interface PlaywrightServerDelegate {
export type PlaywrightServerOptions = {
acceptForwardedPorts?: boolean
+ onDisconnect?: () => void;
};
export class PlaywrightServer {
@@ -40,7 +41,7 @@ export class PlaywrightServer {
private _clientsCount = 0;
private _delegate: PlaywrightServerDelegate;
- static async startDefault({ acceptForwardedPorts }: PlaywrightServerOptions = {}): Promise<PlaywrightServer> {
+ static async startDefault({ acceptForwardedPorts, onDisconnect }: PlaywrightServerOptions = {}): Promise<PlaywrightServer> {
const cleanup = async () => {
await gracefullyCloseAll().catch(e => {});
};
@@ -57,6 +58,7 @@ export class PlaywrightServer {
cleanup();
playwright._disablePortForwarding();
playwright.selectors.unregisterAll();
+ onDisconnect?.();
};
},
};
diff --git a/tests/config/baseTest.ts b/tests/config/baseTest.ts
index ff4667c72a..770eff2515 100644
--- a/tests/config/baseTest.ts
+++ b/tests/config/baseTest.ts
@@ -57,7 +57,6 @@ class DriverMode {
}
class ServiceMode {
- private _playwrightObejct: any;
private _client: any;
private _serviceProcess: childProcess.ChildProcess;
@@ -75,8 +74,7 @@ class ServiceMode {
});
this._serviceProcess.on('exit', this._onExit);
this._client = await PlaywrightClient.connect({wsEndpoint: `ws://localhost:${port}/ws`});
- this._playwrightObejct = this._client.playwright();
- return this._playwrightObejct;
+ return this._client.playwright();
}
async teardown() {
@@ -87,7 +85,7 @@ class ServiceMode {
await processExited;
}
- private _onExit(exitCode, signal) {
+ private _onExit(exitCode: number, signal: string) {
throw new Error(`Server closed with exitCode=${exitCode} signal=${signal}`);
}
}