salix/e2e/helpers/puppeteer.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-11-25 08:13:20 +00:00
2019-12-12 07:37:35 +00:00
import Puppeteer from 'puppeteer';
import {extendPage} from './extensions';
import {url as defaultURL} from './config';
2019-11-25 08:13:20 +00:00
export async function getBrowser() {
2020-03-24 10:12:59 +00:00
const args = [
`--no-sandbox`,
`--window-size=${ 1920 },${ 1080 }`
];
let env = process.env;
if (env.E2E_DEBUG) {
2020-03-24 10:12:59 +00:00
args.push('--auto-open-devtools-for-tabs');
env.E2E_SHOW = true;
}
2020-03-24 10:12:59 +00:00
const headless = !env.E2E_SHOW;
const browser = await Puppeteer.launch({
2020-03-24 10:12:59 +00:00
args,
defaultViewport: null,
2020-02-04 15:21:10 +00:00
headless: headless,
slowMo: 0, // slow down by ms
2019-12-12 07:37:35 +00:00
});
2020-03-24 10:12:59 +00:00
let page = (await browser.pages())[0];
2020-02-12 13:36:05 +00:00
await page.evaluateOnNewDocument(() => {
Object.defineProperty(navigator, 'language', {
get: function() {
return 'en';
}
});
Object.defineProperty(navigator, 'languages', {
get: function() {
return ['en'];
}
});
});
page = extendPage(page);
page.setDefaultTimeout(4000);
await page.goto(defaultURL, {waitUntil: 'load'});
return {page, close: browser.close.bind(browser)};
2019-12-12 07:37:35 +00:00
}
2019-11-25 08:13:20 +00:00
export default getBrowser;