chore: misc test fixes (#2888)
This commit is contained in:
parent
c3ac0371e6
commit
6209d14f87
|
|
@ -23,6 +23,16 @@ export interface Channel extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface PlaywrightChannel extends Channel {
|
||||||
|
}
|
||||||
|
export type PlaywrightInitializer = {
|
||||||
|
chromium: BrowserTypeChannel,
|
||||||
|
firefox: BrowserTypeChannel,
|
||||||
|
webkit: BrowserTypeChannel,
|
||||||
|
deviceDescriptors: types.Devices,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export interface BrowserTypeChannel extends Channel {
|
export interface BrowserTypeChannel extends Channel {
|
||||||
connect(params: types.ConnectOptions): Promise<BrowserChannel>;
|
connect(params: types.ConnectOptions): Promise<BrowserChannel>;
|
||||||
launch(params: types.LaunchOptions): Promise<BrowserChannel>;
|
launch(params: types.LaunchOptions): Promise<BrowserChannel>;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import { Transport } from './transport';
|
||||||
connection.onmessage = message => transport.send(message);
|
connection.onmessage = message => transport.send(message);
|
||||||
transport.onmessage = message => connection.dispatch(message);
|
transport.onmessage = message => connection.dispatch(message);
|
||||||
|
|
||||||
const chromium = await connection.waitForObjectWithKnownName('chromium');
|
const playwright = await connection.waitForObjectWithKnownName('playwright');
|
||||||
const browser = await chromium.launch({ headless: false });
|
const browser = await playwright.chromium.launch({ headless: false });
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://example.com');
|
await page.goto('https://example.com');
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@ import { ConnectionScope } from './connection';
|
||||||
import { BrowserServer } from './browserServer';
|
import { BrowserServer } from './browserServer';
|
||||||
|
|
||||||
export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeInitializer> {
|
export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeInitializer> {
|
||||||
|
|
||||||
|
static from(browserTyep: BrowserTypeChannel): BrowserType {
|
||||||
|
return (browserTyep as any)._object;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(scope: ConnectionScope, guid: string, initializer: BrowserTypeInitializer) {
|
constructor(scope: ConnectionScope, guid: string, initializer: BrowserTypeInitializer) {
|
||||||
super(scope, guid, initializer);
|
super(scope, guid, initializer);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import { Download } from './download';
|
||||||
import { parseError } from '../serializers';
|
import { parseError } from '../serializers';
|
||||||
import { BrowserServer } from './browserServer';
|
import { BrowserServer } from './browserServer';
|
||||||
import { CDPSession } from './cdpSession';
|
import { CDPSession } from './cdpSession';
|
||||||
|
import { Playwright } from './playwright';
|
||||||
|
|
||||||
export class Connection {
|
export class Connection {
|
||||||
readonly _objects = new Map<string, ChannelOwner<any, any>>();
|
readonly _objects = new Map<string, ChannelOwner<any, any>>();
|
||||||
|
|
@ -221,6 +222,9 @@ export class ConnectionScope {
|
||||||
case 'page':
|
case 'page':
|
||||||
result = new Page(this, guid, initializer);
|
result = new Page(this, guid, initializer);
|
||||||
break;
|
break;
|
||||||
|
case 'playwright':
|
||||||
|
result = new Playwright(this, guid, initializer);
|
||||||
|
break;
|
||||||
case 'request':
|
case 'request':
|
||||||
result = new Request(this, guid, initializer);
|
result = new Request(this, guid, initializer);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
36
src/rpc/client/playwright.ts
Normal file
36
src/rpc/client/playwright.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { PlaywrightChannel, PlaywrightInitializer } from '../channels';
|
||||||
|
import * as types from '../../types';
|
||||||
|
import { BrowserType } from './browserType';
|
||||||
|
import { ChannelOwner } from './channelOwner';
|
||||||
|
import { ConnectionScope } from './connection';
|
||||||
|
|
||||||
|
export class Playwright extends ChannelOwner<PlaywrightChannel, PlaywrightInitializer> {
|
||||||
|
chromium: BrowserType;
|
||||||
|
firefox: BrowserType;
|
||||||
|
webkit: BrowserType;
|
||||||
|
devices: types.Devices;
|
||||||
|
|
||||||
|
constructor(scope: ConnectionScope, guid: string, initializer: PlaywrightInitializer) {
|
||||||
|
super(scope, guid, initializer);
|
||||||
|
this.chromium = BrowserType.from(initializer.chromium);
|
||||||
|
this.firefox = BrowserType.from(initializer.firefox);
|
||||||
|
this.webkit = BrowserType.from(initializer.webkit);
|
||||||
|
this.devices = initializer.deviceDescriptors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
import { Transport } from './transport';
|
import { Transport } from './transport';
|
||||||
import { DispatcherConnection } from './server/dispatcher';
|
import { DispatcherConnection } from './server/dispatcher';
|
||||||
import { Playwright } from '../server/playwright';
|
import { Playwright } from '../server/playwright';
|
||||||
import { BrowserTypeDispatcher } from './server/browserTypeDispatcher';
|
import { PlaywrightDispatcher } from './server/playwrightDispatcher';
|
||||||
|
|
||||||
const dispatcherConnection = new DispatcherConnection();
|
const dispatcherConnection = new DispatcherConnection();
|
||||||
const transport = new Transport(process.stdout, process.stdin);
|
const transport = new Transport(process.stdout, process.stdin);
|
||||||
|
|
@ -25,6 +25,4 @@ transport.onmessage = message => dispatcherConnection.dispatch(message);
|
||||||
dispatcherConnection.onmessage = message => transport.send(message);
|
dispatcherConnection.onmessage = message => transport.send(message);
|
||||||
|
|
||||||
const playwright = new Playwright(__dirname, require('../../browsers.json')['browsers']);
|
const playwright = new Playwright(__dirname, require('../../browsers.json')['browsers']);
|
||||||
new BrowserTypeDispatcher(dispatcherConnection.rootScope(), playwright.chromium!);
|
new PlaywrightDispatcher(dispatcherConnection.rootScope(), playwright);
|
||||||
new BrowserTypeDispatcher(dispatcherConnection.rootScope(), playwright.firefox!);
|
|
||||||
new BrowserTypeDispatcher(dispatcherConnection.rootScope(), playwright.webkit!);
|
|
||||||
|
|
|
||||||
31
src/rpc/server/playwrightDispatcher.ts
Normal file
31
src/rpc/server/playwrightDispatcher.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the 'License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Playwright } from '../../server/playwright';
|
||||||
|
import { PlaywrightChannel, PlaywrightInitializer } from '../channels';
|
||||||
|
import { BrowserTypeDispatcher } from './browserTypeDispatcher';
|
||||||
|
import { Dispatcher, DispatcherScope } from './dispatcher';
|
||||||
|
|
||||||
|
export class PlaywrightDispatcher extends Dispatcher<Playwright, PlaywrightInitializer> implements PlaywrightChannel {
|
||||||
|
constructor(scope: DispatcherScope, playwright: Playwright) {
|
||||||
|
super(scope, playwright, 'playwright', {
|
||||||
|
chromium: new BrowserTypeDispatcher(scope, playwright.chromium!),
|
||||||
|
firefox: new BrowserTypeDispatcher(scope, playwright.firefox!),
|
||||||
|
webkit: new BrowserTypeDispatcher(scope, playwright.webkit!),
|
||||||
|
deviceDescriptors: playwright.devices
|
||||||
|
}, false, 'playwright');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,9 +24,9 @@ describe.skip(!CHANNEL)('Channels', function() {
|
||||||
|
|
||||||
it('should scope context handles', async({browser, server}) => {
|
it('should scope context handles', async({browser, server}) => {
|
||||||
const GOLDEN_PRECONDITION = {
|
const GOLDEN_PRECONDITION = {
|
||||||
objects: [ 'chromium', 'browser' ],
|
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ],
|
||||||
scopes: [
|
scopes: [
|
||||||
{ _guid: '', objects: [ 'chromium', 'browser' ] },
|
{ _guid: '', objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ] },
|
||||||
{ _guid: 'browser', objects: [] }
|
{ _guid: 'browser', objects: [] }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
@ -36,9 +36,9 @@ describe.skip(!CHANNEL)('Channels', function() {
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await expectScopeState(browser, {
|
await expectScopeState(browser, {
|
||||||
objects: [ 'chromium', 'browser', 'context', 'frame', 'page', 'request', 'response' ],
|
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser', 'context', 'frame', 'page', 'request', 'response' ],
|
||||||
scopes: [
|
scopes: [
|
||||||
{ _guid: '', objects: [ 'chromium', 'browser' ] },
|
{ _guid: '', objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ] },
|
||||||
{ _guid: 'browser', objects: ['context'] },
|
{ _guid: 'browser', objects: ['context'] },
|
||||||
{ _guid: 'context', objects: ['frame', 'page', 'request', 'response'] }
|
{ _guid: 'context', objects: ['frame', 'page', 'request', 'response'] }
|
||||||
]
|
]
|
||||||
|
|
@ -50,9 +50,9 @@ describe.skip(!CHANNEL)('Channels', function() {
|
||||||
|
|
||||||
it('should scope CDPSession handles', async({browserType, browser, server}) => {
|
it('should scope CDPSession handles', async({browserType, browser, server}) => {
|
||||||
const GOLDEN_PRECONDITION = {
|
const GOLDEN_PRECONDITION = {
|
||||||
objects: [ 'chromium', 'browser' ],
|
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ],
|
||||||
scopes: [
|
scopes: [
|
||||||
{ _guid: '', objects: [ 'chromium', 'browser' ] },
|
{ _guid: '', objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ] },
|
||||||
{ _guid: 'browser', objects: [] }
|
{ _guid: 'browser', objects: [] }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
@ -60,9 +60,9 @@ describe.skip(!CHANNEL)('Channels', function() {
|
||||||
|
|
||||||
const session = await browser.newBrowserCDPSession();
|
const session = await browser.newBrowserCDPSession();
|
||||||
await expectScopeState(browserType, {
|
await expectScopeState(browserType, {
|
||||||
objects: [ 'chromium', 'browser', 'cdpSession' ],
|
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser', 'cdpSession' ],
|
||||||
scopes: [
|
scopes: [
|
||||||
{ _guid: '', objects: [ 'chromium', 'browser' ] },
|
{ _guid: '', objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ] },
|
||||||
{ _guid: 'browser', objects: ['cdpSession'] },
|
{ _guid: 'browser', objects: ['cdpSession'] },
|
||||||
{ _guid: 'cdpSession', objects: [] },
|
{ _guid: 'cdpSession', objects: [] },
|
||||||
]
|
]
|
||||||
|
|
@ -74,9 +74,9 @@ describe.skip(!CHANNEL)('Channels', function() {
|
||||||
|
|
||||||
it('should scope browser handles', async({browserType, defaultBrowserOptions}) => {
|
it('should scope browser handles', async({browserType, defaultBrowserOptions}) => {
|
||||||
const GOLDEN_PRECONDITION = {
|
const GOLDEN_PRECONDITION = {
|
||||||
objects: [ 'chromium', 'browser' ],
|
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ],
|
||||||
scopes: [
|
scopes: [
|
||||||
{ _guid: '', objects: [ 'chromium', 'browser' ] },
|
{ _guid: '', objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ] },
|
||||||
{ _guid: 'browser', objects: [] }
|
{ _guid: 'browser', objects: [] }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
@ -85,9 +85,9 @@ describe.skip(!CHANNEL)('Channels', function() {
|
||||||
const browser = await browserType.launch(defaultBrowserOptions);
|
const browser = await browserType.launch(defaultBrowserOptions);
|
||||||
await browser.newContext();
|
await browser.newContext();
|
||||||
await expectScopeState(browserType, {
|
await expectScopeState(browserType, {
|
||||||
objects: [ 'chromium', 'browser', 'browser', 'context' ],
|
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser', 'browser', 'context' ],
|
||||||
scopes: [
|
scopes: [
|
||||||
{ _guid: '', objects: [ 'chromium', 'browser', 'browser' ] },
|
{ _guid: '', objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser', 'browser' ] },
|
||||||
{ _guid: 'browser', objects: [] },
|
{ _guid: 'browser', objects: [] },
|
||||||
{ _guid: 'browser', objects: ['context'] },
|
{ _guid: 'browser', objects: ['context'] },
|
||||||
{ _guid: 'context', objects: [] },
|
{ _guid: 'context', objects: [] },
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ const rm = require('rimraf').sync;
|
||||||
const {TestServer} = require('../utils/testserver/');
|
const {TestServer} = require('../utils/testserver/');
|
||||||
const { DispatcherConnection } = require('../lib/rpc/server/dispatcher');
|
const { DispatcherConnection } = require('../lib/rpc/server/dispatcher');
|
||||||
const { Connection } = require('../lib/rpc/client/connection');
|
const { Connection } = require('../lib/rpc/client/connection');
|
||||||
const { BrowserTypeDispatcher } = require('../lib/rpc/server/browserTypeDispatcher');
|
const { PlaywrightDispatcher } = require('../lib/rpc/server/playwrightDispatcher');
|
||||||
|
|
||||||
class ServerEnvironment {
|
class ServerEnvironment {
|
||||||
async beforeAll(state) {
|
async beforeAll(state) {
|
||||||
|
|
@ -159,18 +159,10 @@ class PlaywrightEnvironment {
|
||||||
}
|
}
|
||||||
|
|
||||||
name() { return 'Playwright'; };
|
name() { return 'Playwright'; };
|
||||||
beforeAll(state) { state.playwright = this._playwright; }
|
|
||||||
afterAll(state) { delete state.playwright; }
|
|
||||||
}
|
|
||||||
|
|
||||||
class BrowserTypeEnvironment {
|
|
||||||
constructor(browserType) {
|
|
||||||
this._browserType = browserType;
|
|
||||||
}
|
|
||||||
|
|
||||||
async beforeAll(state) {
|
async beforeAll(state) {
|
||||||
// Channel substitute
|
// Channel substitute
|
||||||
let overridenBrowserType = this._browserType;
|
this.overriddenPlaywright = this._playwright;
|
||||||
if (process.env.PWCHANNEL) {
|
if (process.env.PWCHANNEL) {
|
||||||
const dispatcherConnection = new DispatcherConnection();
|
const dispatcherConnection = new DispatcherConnection();
|
||||||
const connection = new Connection();
|
const connection = new Connection();
|
||||||
|
|
@ -182,10 +174,24 @@ class BrowserTypeEnvironment {
|
||||||
await new Promise(f => setImmediate(f));
|
await new Promise(f => setImmediate(f));
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
new BrowserTypeDispatcher(dispatcherConnection.rootScope(), this._browserType);
|
new PlaywrightDispatcher(dispatcherConnection.rootScope(), this._playwright);
|
||||||
overridenBrowserType = await connection.waitForObjectWithKnownName(this._browserType.name());
|
this.overriddenPlaywright = await connection.waitForObjectWithKnownName('playwright');
|
||||||
}
|
}
|
||||||
state.browserType = overridenBrowserType;
|
state.playwright = this.overriddenPlaywright;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterAll(state) {
|
||||||
|
delete state.playwright;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BrowserTypeEnvironment {
|
||||||
|
constructor(browserName) {
|
||||||
|
this._browserName = browserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeAll(state) {
|
||||||
|
state.browserType = state.playwright[this._browserName];
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterAll(state) {
|
async afterAll(state) {
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ function makeTestRunnerInfo() {
|
||||||
const browserInfo = browserNames.map(browserName => {
|
const browserInfo = browserNames.map(browserName => {
|
||||||
const browserType = playwright[browserName];
|
const browserType = playwright[browserName];
|
||||||
|
|
||||||
const browserTypeEnvironment = new BrowserTypeEnvironment(browserType);
|
const browserTypeEnvironment = new BrowserTypeEnvironment(browserName);
|
||||||
|
|
||||||
// TODO: maybe launch options per browser?
|
// TODO: maybe launch options per browser?
|
||||||
const launchOptions = {
|
const launchOptions = {
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,8 @@ function collect(browserNames) {
|
||||||
const { setUnderTest } = require(require('path').join(playwrightPath, 'lib/helper.js'));
|
const { setUnderTest } = require(require('path').join(playwrightPath, 'lib/helper.js'));
|
||||||
setUnderTest();
|
setUnderTest();
|
||||||
|
|
||||||
testRunner.collector().useEnvironment(new PlaywrightEnvironment(playwright));
|
const playwrightEnvironment = new PlaywrightEnvironment(playwright);
|
||||||
|
testRunner.collector().useEnvironment(playwrightEnvironment);
|
||||||
for (const e of config.globalEnvironments || [])
|
for (const e of config.globalEnvironments || [])
|
||||||
testRunner.collector().useEnvironment(e);
|
testRunner.collector().useEnvironment(e);
|
||||||
|
|
||||||
|
|
@ -90,7 +91,7 @@ function collect(browserNames) {
|
||||||
|
|
||||||
for (const browserName of browserNames) {
|
for (const browserName of browserNames) {
|
||||||
const browserType = playwright[browserName];
|
const browserType = playwright[browserName];
|
||||||
const browserTypeEnvironment = new BrowserTypeEnvironment(browserType);
|
const browserTypeEnvironment = new BrowserTypeEnvironment(browserName);
|
||||||
|
|
||||||
// TODO: maybe launch options per browser?
|
// TODO: maybe launch options per browser?
|
||||||
const launchOptions = {
|
const launchOptions = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue