Skip to content

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

feat(driver): add reuse and navigate commands (#16420)

Pavel Feldmanc84fbc2e4e25
diff --git a/packages/playwright-core/src/cli/driver.ts b/packages/playwright-core/src/cli/driver.ts
index b36d3fb330..34b75ac0f6 100644
--- a/packages/playwright-core/src/cli/driver.ts
+++ b/packages/playwright-core/src/cli/driver.ts
@@ -92,6 +92,19 @@ class ProtocolHandler {
this._playwright = playwright;
}
+ async resetForReuse() {
+ const contexts = new Set<BrowserContext>();
+ for (const page of this._playwright.allPages())
+ contexts.add(page.context());
+ for (const context of contexts)
+ await context.resetForReuse(internalMetadata, null);
+ }
+
+ async navigate(params: { url: string }) {
+ for (const p of this._playwright.allPages())
+ await p.mainFrame().goto(internalMetadata, params.url);
+ }
+
async setMode(params: { mode: Mode, language?: string, file?: string }) {
await gc(this._playwright);
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts
index 8510569f89..dd81f05297 100644
--- a/packages/playwright-core/src/server/browserContext.ts
+++ b/packages/playwright-core/src/server/browserContext.ts
@@ -157,12 +157,14 @@ export abstract class BrowserContext extends SdkObject {
return JSON.stringify(paramsCopy);
}
- async resetForReuse(metadata: CallMetadata, params: channels.BrowserNewContextForReuseParams) {
+ async resetForReuse(metadata: CallMetadata, params: channels.BrowserNewContextForReuseParams | null) {
this.setDefaultNavigationTimeout(undefined);
this.setDefaultTimeout(undefined);
- for (const key of paramsThatAllowContextReuse)
- (this._options as any)[key] = params[key];
+ if (params) {
+ for (const key of paramsThatAllowContextReuse)
+ (this._options as any)[key] = params[key];
+ }
await this._cancelAllRoutesInFlight();