feat(connect): add connectOptions.timeout (#13163)
This commit is contained in:
parent
aa1daeba85
commit
eb09306db2
|
|
@ -115,7 +115,7 @@ Logger sink for Playwright logging. Optional.
|
|||
- `timeout` <[float]>
|
||||
|
||||
Maximum time in milliseconds to wait for the connection to be established. Defaults to
|
||||
`30000` (30 seconds). Pass `0` to disable timeout.
|
||||
`0` (no timeout).
|
||||
|
||||
## async method: BrowserType.connectOverCDP
|
||||
- returns: <[Browser]>
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ Learn more about [various timeouts](../test-timeouts.md).
|
|||
- type: <[void]|[Object]>
|
||||
- `wsEndpoint` <[string]> A browser websocket endpoint to connect to.
|
||||
- `headers` <[void]|[Object]<[string], [string]>> Additional HTTP headers to be sent with web socket connect request. Optional.
|
||||
- `timeout` <[int]> Timeout in milliseconds for the connection to be established. Optional, defaults to no timeout.
|
||||
|
||||
When connect options are specified, default [`property: Fixtures.browser`], [`property: Fixtures.context`] and [`property: Fixtures.page`] use the remote browser instead of launching a browser locally, and any launch options like [`property: TestOptions.headless`] or [`property: TestOptions.channel`] are ignored.
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ export class WebSocketTransport implements ConnectionTransport {
|
|||
this._ws = new WebSocket(url, [], {
|
||||
perMessageDeflate: false,
|
||||
maxPayload: 256 * 1024 * 1024, // 256Mb,
|
||||
handshakeTimeout: progress.timeUntilDeadline(),
|
||||
// Prevent internal http client error when passing negative timeout.
|
||||
handshakeTimeout: Math.max(progress.timeUntilDeadline(), 1),
|
||||
headers,
|
||||
followRedirects,
|
||||
});
|
||||
|
|
|
|||
3
packages/playwright-core/types/types.d.ts
vendored
3
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -15715,8 +15715,7 @@ export interface ConnectOptions {
|
|||
slowMo?: number;
|
||||
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the connection to be established. Defaults to `30000` (30 seconds). Pass `0` to
|
||||
* disable timeout.
|
||||
* Maximum time in milliseconds to wait for the connection to be established. Defaults to `0` (no timeout).
|
||||
*/
|
||||
timeout?: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,8 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
|||
'x-playwright-browser': channel || browserName,
|
||||
'x-playwright-headless': headless ? '1' : '0',
|
||||
...connectOptions.headers,
|
||||
}
|
||||
},
|
||||
timeout: connectOptions.timeout,
|
||||
});
|
||||
await use(browser);
|
||||
await browser.close();
|
||||
|
|
|
|||
5
packages/playwright-test/types/test.d.ts
vendored
5
packages/playwright-test/types/test.d.ts
vendored
|
|
@ -2853,6 +2853,11 @@ type ConnectOptions = {
|
|||
* Additional HTTP headers to be sent with web socket connect request.
|
||||
*/
|
||||
headers?: { [key: string]: string; };
|
||||
|
||||
/**
|
||||
* Timeout in milliseconds for the connection to be established. Optional, defaults to no timeout.
|
||||
*/
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -620,3 +620,26 @@ test('should throw with bad connectOptions', async ({ runInlineTest }) => {
|
|||
expect(result.passed).toBe(0);
|
||||
expect(result.output).toContain('browserType.connect:');
|
||||
});
|
||||
|
||||
test('should respect connectOptions.timeout', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'playwright.config.js': `
|
||||
module.exports = {
|
||||
use: {
|
||||
connectOptions: {
|
||||
wsEndpoint: 'wss://locahost:5678',
|
||||
timeout: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
`,
|
||||
'a.test.ts': `
|
||||
const { test } = pwt;
|
||||
test('pass', async ({ page }) => {
|
||||
});
|
||||
`,
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.passed).toBe(0);
|
||||
expect(result.output).toContain('browserType.connect: Timeout 1ms exceeded.');
|
||||
});
|
||||
|
|
|
|||
5
utils/generate_types/overrides-test.d.ts
vendored
5
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -369,6 +369,11 @@ type ConnectOptions = {
|
|||
* Additional HTTP headers to be sent with web socket connect request.
|
||||
*/
|
||||
headers?: { [key: string]: string; };
|
||||
|
||||
/**
|
||||
* Timeout in milliseconds for the connection to be established. Optional, defaults to no timeout.
|
||||
*/
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
export interface PlaywrightWorkerOptions {
|
||||
|
|
|
|||
Loading…
Reference in a new issue