Skip to content

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

test: add a test for newCDPSession rejecting on non-pages (#3353)

Dmitry Gozman7e2cc77524e1
diff --git a/src/chromium/crBrowser.ts b/src/chromium/crBrowser.ts
index 12218570dd..7e7389ee79 100644
--- a/src/chromium/crBrowser.ts
+++ b/src/chromium/crBrowser.ts
@@ -463,6 +463,8 @@ export class CRBrowserContext extends BrowserContextBase {
}
async newCDPSession(page: Page): Promise<CRSession> {
+ if (!(page instanceof Page))
+ throw new Error('page: expected Page');
const targetId = (page._delegate as CRPage)._targetId;
const rootSession = await this._browser._clientRootSession();
const { sessionId } = await rootSession.send('Target.attachToTarget', { targetId, flatten: true });
diff --git a/test/chromium/session.spec.js b/test/chromium/session.spec.js
index b31783f7bb..60558021b9 100644
--- a/test/chromium/session.spec.js
+++ b/test/chromium/session.spec.js
@@ -36,6 +36,11 @@ it.skip(!CHROMIUM)('should send events', async function({page, server}) {
expect(events.length).toBe(1);
});
+it.skip(!CHROMIUM)('should only accept a page', async function({page}) {
+ const error = await page.context().newCDPSession(page.context()).catch(e => e);
+ expect(error.message).toContain('page: expected Page');
+});
+
it.skip(!CHROMIUM)('should enable and disable domains independently', async function({page}) {
const client = await page.context().newCDPSession(page);
await client.send('Runtime.enable');