Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(test): properly handle custom executable path (#1723)
Dmitry Gozman1b366b0fc54b
diff --git a/test/playwright.spec.js b/test/playwright.spec.jsindex 8d065d0daf..253ef9cd94 100644--- a/test/playwright.spec.js+++ b/test/playwright.spec.js@@ -99,10 +99,31 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {delete state.browserType;});+ const browserType = playwright[product.toLowerCase()];+ const executablePath = {+ 'chromium': process.env.CRPATH,+ 'firefox': process.env.FFPATH,+ 'webkit': process.env.WKPATH,+ }[browserType.name()];+ if (executablePath) {+ const YELLOW_COLOR = '\x1b[33m';+ const RESET_COLOR = '\x1b[0m';+ console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${executablePath}${RESET_COLOR}`);+ browserType._executablePath = executablePath;+ } else {+ // Make sure the `npm install` was run after the chromium roll.+ if (!fs.existsSync(browserType.executablePath()))+ throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`);+ }+ const launchOptions = {+ handleSIGINT: false,+ slowMo: valueFromEnv('SLOW_MO', 0),+ headless: !!valueFromEnv('HEADLESS', true),+ };+const browserEnvironment = new Environment(product);browserEnvironment.beforeAll(async state => {- const { defaultBrowserOptions } = require('./utils').testOptions(state.browserType);- state.browser = await state.browserType.launch(defaultBrowserOptions);+ state.browser = await state.browserType.launch(launchOptions);state.browserServer = state.browser._ownedServer;state._stdout = readline.createInterface({ input: state.browserServer.process().stdout });state._stderr = readline.createInterface({ input: state.browserServer.process().stderr });@@ -156,7 +177,7 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {describe(product, () => {// In addition to state, expose these two on global so that describes can access them.global.playwright = playwright;- global.browserType = playwright[product.toLowerCase()];+ global.browserType = browserType;testRunner.collector().useEnvironment(browserTypeEnvironment);testRunner.collector().useEnvironment(goldenEnvironment); // Custom environment.diff --git a/test/utils.js b/test/utils.jsindex c296e797e9..3ce7a55f94 100644--- a/test/utils.js+++ b/test/utils.js@@ -216,26 +216,11 @@ const utils = module.exports = {testOptions(browserType) {const headless = !!valueFromEnv('HEADLESS', true);- const executablePath = {- 'chromium': process.env.CRPATH,- 'firefox': process.env.FFPATH,- 'webkit': process.env.WKPATH,- }[browserType.name()];const defaultBrowserOptions = {handleSIGINT: false,- executablePath,slowMo: valueFromEnv('SLOW_MO', 0),headless,};- if (defaultBrowserOptions.executablePath) {- const YELLOW_COLOR = '\x1b[33m';- const RESET_COLOR = '\x1b[0m';- console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}${RESET_COLOR}`);- } else {- // Make sure the `npm install` was run after the chromium roll.- if (!fs.existsSync(browserType.executablePath()))- throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`);- }const GOLDEN_DIR = path.join(__dirname, 'golden-' + browserType.name());const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name());return {@@ -248,7 +233,7 @@ const utils = module.exports = {browserType,defaultBrowserOptions,playwrightPath: PROJECT_ROOT,- headless: !!defaultBrowserOptions.headless,+ headless,GOLDEN_DIR,OUTPUT_DIR,};