mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test): properly handle custom executable path (#1723)
This commit is contained in:
parent
b385ea8415
commit
1b366b0fc5
@ -99,10 +99,31 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
|
|||||||
delete state.browserType;
|
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);
|
const browserEnvironment = new Environment(product);
|
||||||
browserEnvironment.beforeAll(async state => {
|
browserEnvironment.beforeAll(async state => {
|
||||||
const { defaultBrowserOptions } = require('./utils').testOptions(state.browserType);
|
state.browser = await state.browserType.launch(launchOptions);
|
||||||
state.browser = await state.browserType.launch(defaultBrowserOptions);
|
|
||||||
state.browserServer = state.browser._ownedServer;
|
state.browserServer = state.browser._ownedServer;
|
||||||
state._stdout = readline.createInterface({ input: state.browserServer.process().stdout });
|
state._stdout = readline.createInterface({ input: state.browserServer.process().stdout });
|
||||||
state._stderr = readline.createInterface({ input: state.browserServer.process().stderr });
|
state._stderr = readline.createInterface({ input: state.browserServer.process().stderr });
|
||||||
@ -156,7 +177,7 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
|
|||||||
describe(product, () => {
|
describe(product, () => {
|
||||||
// In addition to state, expose these two on global so that describes can access them.
|
// In addition to state, expose these two on global so that describes can access them.
|
||||||
global.playwright = playwright;
|
global.playwright = playwright;
|
||||||
global.browserType = playwright[product.toLowerCase()];
|
global.browserType = browserType;
|
||||||
|
|
||||||
testRunner.collector().useEnvironment(browserTypeEnvironment);
|
testRunner.collector().useEnvironment(browserTypeEnvironment);
|
||||||
testRunner.collector().useEnvironment(goldenEnvironment); // Custom environment.
|
testRunner.collector().useEnvironment(goldenEnvironment); // Custom environment.
|
||||||
|
@ -216,26 +216,11 @@ const utils = module.exports = {
|
|||||||
|
|
||||||
testOptions(browserType) {
|
testOptions(browserType) {
|
||||||
const headless = !!valueFromEnv('HEADLESS', true);
|
const headless = !!valueFromEnv('HEADLESS', true);
|
||||||
const executablePath = {
|
|
||||||
'chromium': process.env.CRPATH,
|
|
||||||
'firefox': process.env.FFPATH,
|
|
||||||
'webkit': process.env.WKPATH,
|
|
||||||
}[browserType.name()];
|
|
||||||
const defaultBrowserOptions = {
|
const defaultBrowserOptions = {
|
||||||
handleSIGINT: false,
|
handleSIGINT: false,
|
||||||
executablePath,
|
|
||||||
slowMo: valueFromEnv('SLOW_MO', 0),
|
slowMo: valueFromEnv('SLOW_MO', 0),
|
||||||
headless,
|
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 GOLDEN_DIR = path.join(__dirname, 'golden-' + browserType.name());
|
||||||
const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name());
|
const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name());
|
||||||
return {
|
return {
|
||||||
@ -248,7 +233,7 @@ const utils = module.exports = {
|
|||||||
browserType,
|
browserType,
|
||||||
defaultBrowserOptions,
|
defaultBrowserOptions,
|
||||||
playwrightPath: PROJECT_ROOT,
|
playwrightPath: PROJECT_ROOT,
|
||||||
headless: !!defaultBrowserOptions.headless,
|
headless,
|
||||||
GOLDEN_DIR,
|
GOLDEN_DIR,
|
||||||
OUTPUT_DIR,
|
OUTPUT_DIR,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user