mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
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.
35 lines
802 B
JavaScript
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;
|