Files
zulip/frontend_tests/puppeteer_lib/common.js
Priyank Patel 41447a0d5c puppeteer: Add a common module for resuable code.
In common.js, we now have a single browser instance for the whole
test. When we update the test-js-with-puppetter to spawn a single
node process, like we do for node tests, we will save time on having
to open an new browser for every test + puppetter start up cost.

We will also add some more helpers here like a method for
filling out a form easily etc.
2020-05-19 15:58:04 -07:00

35 lines
802 B
JavaScript

const puppeteer = require('puppeteer');
class CommonUtils {
constructor() {
this.browser = null;
}
async ensure_browser() {
if (this.browser === null) {
this.browser = await puppeteer.launch({
args: [
'--window-size=1400,1024',
'--no-sandbox', '--disable-setuid-sandbox',
],
defaultViewport: { width: 1280, height: 1024 },
headless: true,
});
}
}
async get_page(url = null) {
await this.ensure_browser();
const page = await this.browser.newPage();
if (url !== null) {
await page.goto(url);
}
return page;
}
}
const common = new CommonUtils();
module.exports = common;