mirror of https://github.com/zulip/zulip.git
puppeteer: Add screenshot method to common module.
This will be useful for debugging purposes and we'll use it to take a screenshot on failure.
This commit is contained in:
parent
1f367ed537
commit
b2f566f53e
|
@ -1,8 +1,10 @@
|
|||
const path = require('path');
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
class CommonUtils {
|
||||
constructor() {
|
||||
this.browser = null;
|
||||
this.screenshot_id = 0;
|
||||
}
|
||||
|
||||
async ensure_browser() {
|
||||
|
@ -29,6 +31,19 @@ class CommonUtils {
|
|||
return page;
|
||||
}
|
||||
|
||||
async screenshot(page, name = null) {
|
||||
if (name === null) {
|
||||
name = `${this.screenshot_id}`;
|
||||
this.screenshot_id += 1;
|
||||
}
|
||||
|
||||
const root_dir = path.resolve(__dirname, '../../');
|
||||
const screenshot_path = path.join(root_dir, 'var/puppeteer', `${name}.png`);
|
||||
await page.screenshot({
|
||||
path: screenshot_path,
|
||||
});
|
||||
}
|
||||
|
||||
async run_test(test_function) {
|
||||
try {
|
||||
await test_function();
|
||||
|
|
Loading…
Reference in New Issue