salix/e2e/helpers/puppeteer.js

36 lines
839 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({
defaultViewport: null,
headless: false,
slowMo: 0, // slow down by ms
// devtools: true,
});
}
2019-11-25 08:13:20 +00:00
const page = await browser.newPage();
2019-12-12 07:37:35 +00:00
await page._client.send('Network.clearBrowserCookies');
await page.goto(url);
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;