salix/e2e/helpers/puppeteer.js

39 lines
928 B
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
2019-12-12 07:37:35 +00:00
let browser;
export function getBrowser() {
return browser || {close: () => {}};
}
async function openPage(url = defaultURL) {
if (!browser) {
browser = await Puppeteer.launch({
2019-12-31 11:00:16 +00:00
args: [
'--start-maximized'
// '--start-fullscreen'
],
2019-12-12 07:37:35 +00:00
defaultViewport: null,
headless: false,
slowMo: 0, // slow down by ms
});
}
2019-11-25 08:13:20 +00:00
const page = await browser.newPage();
2019-12-31 11:00:16 +00:00
await page.setDefaultTimeout(5000);
await page.goto(url, {waitUntil: 'networkidle0'});
2019-12-12 07:37:35 +00:00
page.on('console', msg => {
let type = msg.type();
if (type === 'error')
console[type](msg.text());
});
const extendedPage = extendPage(page);
return extendedPage;
}
2019-11-25 08:13:20 +00:00
2019-12-12 07:37:35 +00:00
export default openPage;