fix(selectors): allow custom engines in out-of-process (#17139)
This commit is contained in:
parent
f0c5810609
commit
8d25f2ef59
|
|
@ -25,6 +25,7 @@ export { expect } from './expect';
|
||||||
export const _baseTest: TestType<{}, {}> = rootTestType.test;
|
export const _baseTest: TestType<{}, {}> = rootTestType.test;
|
||||||
export { addRunnerPlugin as _addRunnerPlugin } from './plugins';
|
export { addRunnerPlugin as _addRunnerPlugin } from './plugins';
|
||||||
import * as outOfProcess from 'playwright-core/lib/outofprocess';
|
import * as outOfProcess from 'playwright-core/lib/outofprocess';
|
||||||
|
import * as playwrightLibrary from 'playwright-core';
|
||||||
import type { TestInfoImpl } from './testInfo';
|
import type { TestInfoImpl } from './testInfo';
|
||||||
|
|
||||||
if ((process as any)['__pw_initiator__']) {
|
if ((process as any)['__pw_initiator__']) {
|
||||||
|
|
@ -61,7 +62,9 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
const impl = await outOfProcess.start({
|
const impl = await outOfProcess.start({
|
||||||
NODE_OPTIONS: undefined // Hide driver process while debugging.
|
NODE_OPTIONS: undefined // Hide driver process while debugging.
|
||||||
});
|
});
|
||||||
await use(impl.playwright as any);
|
const pw = impl.playwright as any;
|
||||||
|
pw._setSelectors(playwrightLibrary.selectors);
|
||||||
|
await use(pw);
|
||||||
await impl.stop();
|
await impl.stop();
|
||||||
} else {
|
} else {
|
||||||
await use(require('playwright-core'));
|
await use(require('playwright-core'));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
import { test } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
import type { TestModeName } from './testMode';
|
import type { TestModeName } from './testMode';
|
||||||
import { DefaultTestMode, DriverTestMode } from './testMode';
|
import { DefaultTestMode, DriverTestMode } from './testMode';
|
||||||
|
import * as playwrightLibrary from 'playwright-core';
|
||||||
|
|
||||||
export type TestModeWorkerOptions = {
|
export type TestModeWorkerOptions = {
|
||||||
mode: TestModeName;
|
mode: TestModeName;
|
||||||
|
|
@ -42,6 +43,7 @@ export const testModeTest = test.extend<TestModeTestFixtures, TestModeWorkerOpti
|
||||||
}[mode];
|
}[mode];
|
||||||
require('playwright-core/lib/utils').setUnderTest();
|
require('playwright-core/lib/utils').setUnderTest();
|
||||||
const playwright = await testMode.setup();
|
const playwright = await testMode.setup();
|
||||||
|
playwright._setSelectors(playwrightLibrary.selectors);
|
||||||
await run(playwright);
|
await run(playwright);
|
||||||
await testMode.teardown();
|
await testMode.teardown();
|
||||||
}, { scope: 'worker' }],
|
}, { scope: 'worker' }],
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,16 @@
|
||||||
|
|
||||||
import { browserTest as it, expect } from '../config/browserTest';
|
import { browserTest as it, expect } from '../config/browserTest';
|
||||||
|
|
||||||
|
const createTagSelector = () => ({
|
||||||
|
query(root, selector) {
|
||||||
|
return root.querySelector(selector);
|
||||||
|
},
|
||||||
|
queryAll(root, selector) {
|
||||||
|
return Array.from(root.querySelectorAll(selector));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should work', async ({ playwright, browser }) => {
|
it('should work', async ({ playwright, browser }) => {
|
||||||
const createTagSelector = () => ({
|
|
||||||
query(root, selector) {
|
|
||||||
return root.querySelector(selector);
|
|
||||||
},
|
|
||||||
queryAll(root, selector) {
|
|
||||||
return Array.from(root.querySelectorAll(selector));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Register one engine before creating context.
|
// Register one engine before creating context.
|
||||||
await playwright.selectors.register('tag', `(${createTagSelector.toString()})()`);
|
await playwright.selectors.register('tag', `(${createTagSelector.toString()})()`);
|
||||||
|
|
||||||
|
|
@ -51,6 +52,27 @@ it('should work', async ({ playwright, browser }) => {
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should work when registered on global', async ({ browser }) => {
|
||||||
|
await require('@playwright/test').selectors.register('oop-tag', `(${createTagSelector.toString()})()`);
|
||||||
|
|
||||||
|
const context = await browser.newContext();
|
||||||
|
// Register another engine after creating context.
|
||||||
|
await require('@playwright/test').selectors.register('oop-tag2', `(${createTagSelector.toString()})()`);
|
||||||
|
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.setContent('<div><span></span></div><div></div>');
|
||||||
|
|
||||||
|
expect(await page.$eval('oop-tag=DIV', e => e.nodeName)).toBe('DIV');
|
||||||
|
expect(await page.$eval('oop-tag=SPAN', e => e.nodeName)).toBe('SPAN');
|
||||||
|
expect(await page.$$eval('oop-tag=DIV', es => es.length)).toBe(2);
|
||||||
|
|
||||||
|
expect(await page.$eval('oop-tag2=DIV', e => e.nodeName)).toBe('DIV');
|
||||||
|
expect(await page.$eval('oop-tag2=SPAN', e => e.nodeName)).toBe('SPAN');
|
||||||
|
expect(await page.$$eval('oop-tag2=DIV', es => es.length)).toBe(2);
|
||||||
|
|
||||||
|
await context.close();
|
||||||
|
});
|
||||||
|
|
||||||
it('should work with path', async ({ playwright, browser, asset }) => {
|
it('should work with path', async ({ playwright, browser, asset }) => {
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await playwright.selectors.register('foo', { path: asset('sectionselectorengine.js') });
|
await playwright.selectors.register('foo', { path: asset('sectionselectorengine.js') });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue