test: pass protocol in Puppeteer.connect in tests (#11342)

Add an internal field protocol: 'cdp' | 'webDriverBiDi' to the Browser and use is in tests when Puppeter.connect(...) is called.

Co-authored-by: Maksim Sadym <sadym@google.com>
This commit is contained in:
Maksim Sadym 2023-11-10 13:55:08 +01:00 committed by GitHub
parent b829f42074
commit 0533764aac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 9 deletions

View File

@ -437,4 +437,9 @@ export abstract class Browser extends EventEmitter<BrowserEvents> {
[asyncDisposeSymbol](): Promise<void> {
return this.close();
}
/**
* @internal
*/
abstract get protocol(): 'cdp' | 'webDriverBiDi';
}

View File

@ -57,6 +57,8 @@ export interface BidiBrowserOptions {
* @internal
*/
export class BidiBrowser extends Browser {
readonly protocol = 'webDriverBiDi';
// TODO: Update generator to include fully module
static readonly subscribeModules: string[] = [
'browsingContext',

View File

@ -53,6 +53,8 @@ import {TargetManagerEvent, type TargetManager} from './TargetManager.js';
* @internal
*/
export class CdpBrowser extends BrowserBase {
readonly protocol = 'cdp';
static async _create(
product: 'firefox' | 'chrome' | undefined,
connection: Connection,

View File

@ -381,13 +381,13 @@
"testIdPattern": "[browser.spec] Browser specs Browser.isConnected should set the browser connected state",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browser.spec] Browser specs Browser.process should not return child_process for remote browser",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browser.spec] Browser specs Browser.process should return child_process instance",
@ -2031,19 +2031,19 @@
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should be able to close remote browser",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should be able to connect multiple times to the same browser",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should be able to connect to a browser with no page targets",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should be able to connect to a browser with no page targets",
@ -2061,7 +2061,7 @@
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should be able to connect to the same page simultaneously",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should be able to reconnect to a disconnected browser",
@ -2073,13 +2073,13 @@
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should support ignoreHTTPSErrors option",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should support targetFilter option",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
"expectations": ["FAIL"]
},
{
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.connect should support targetFilter option",

View File

@ -67,6 +67,7 @@ describe('Browser specs', function () {
const browserWSEndpoint = browser.wsEndpoint();
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
expect(remoteBrowser.process()).toBe(null);
remoteBrowser.disconnect();
@ -80,6 +81,7 @@ describe('Browser specs', function () {
const browserWSEndpoint = browser.wsEndpoint();
const newBrowser = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
expect(newBrowser.isConnected()).toBe(true);
newBrowser.disconnect();

View File

@ -226,6 +226,7 @@ describe('BrowserContext', function () {
expect(browser.browserContexts()).toHaveLength(2);
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
const contexts = remoteBrowser.browserContexts();
expect(contexts).toHaveLength(2);

View File

@ -43,6 +43,7 @@ describe('Launcher specs', function () {
try {
const remote = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
const page = await remote.newPage();
const navigationPromise = page
@ -69,6 +70,7 @@ describe('Launcher specs', function () {
try {
const remote = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
const page = await remote.newPage();
const watchdog = page
@ -90,6 +92,7 @@ describe('Launcher specs', function () {
try {
const remote = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
const newPage = await remote.newPage();
const results = await Promise.all([
@ -624,6 +627,7 @@ describe('Launcher specs', function () {
try {
const otherBrowser = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
const page = await otherBrowser.newPage();
expect(
@ -648,6 +652,7 @@ describe('Launcher specs', function () {
try {
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
await Promise.all([
waitEvent(browser, 'disconnected'),
@ -669,6 +674,7 @@ describe('Launcher specs', function () {
);
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint: browser.wsEndpoint(),
protocol: browser.protocol,
});
await Promise.all([
waitEvent(browser, 'disconnected'),
@ -691,6 +697,7 @@ describe('Launcher specs', function () {
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint,
ignoreHTTPSErrors: true,
protocol: browser.protocol,
});
const page = await remoteBrowser.newPage();
let error!: Error;
@ -758,6 +765,7 @@ describe('Launcher specs', function () {
targetFilter: target => {
return !target.url().includes('should-be-ignored');
},
protocol: browser.protocol,
});
const pages = await remoteBrowser.pages();
@ -786,7 +794,10 @@ describe('Launcher specs', function () {
await page.goto(server.PREFIX + '/frames/nested-frames.html');
browser.disconnect();
const remoteBrowser = await puppeteer.connect({browserWSEndpoint});
const remoteBrowser = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
const pages = await remoteBrowser.pages();
const restoredPage = pages.find(page => {
return page.url() === server.PREFIX + '/frames/nested-frames.html';
@ -815,6 +826,7 @@ describe('Launcher specs', function () {
try {
const browserTwo = await puppeteer.connect({
browserWSEndpoint: browserOne.wsEndpoint(),
protocol: browserOne.protocol,
});
const [page1, page2] = await Promise.all([
new Promise<Page | null>(x => {
@ -854,6 +866,7 @@ describe('Launcher specs', function () {
const browserTwo = await puppeteer.connect({
browserWSEndpoint,
protocol: browserOne.protocol,
});
const pages = await browserTwo.pages();
const pageTwo = pages.find(page => {
@ -951,9 +964,11 @@ describe('Launcher specs', function () {
const browserWSEndpoint = browser.wsEndpoint();
const remoteBrowser1 = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
const remoteBrowser2 = await puppeteer.connect({
browserWSEndpoint,
protocol: browser.protocol,
});
let disconnectedOriginal = 0;