puppeteer: Take screenshot on failure.

To take a screenshot on failure where we have our common error
handling code in common.run_test method we need to have access to
the Page instance. Currently, we create a new Page in the test method
we pass into run_test, so we pass in a new Page instance to that method
so the test and the run_test method have access to the same Page. And,
then we take a screenshot on failure. It will be saved as `failure-${num}`
in var/puppeteer directory.
This commit is contained in:
Priyank Patel
2020-05-16 17:14:31 +00:00
committed by Tim Abbott
parent 74e9019922
commit 0b698d1173
3 changed files with 13 additions and 5 deletions

View File

@@ -45,10 +45,18 @@ class CommonUtils {
}
async run_test(test_function) {
// Pass a page instance to test so we can take
// a screenshot of it when the test fails.
const page = await this.get_page();
try {
await test_function();
await test_function(page);
} catch (e) {
console.log(e);
// Take a screenshot, and increment the screenshot_id.
await this.screenshot(page, `failure-${this.screenshot_id}`);
this.screenshot_id += 1;
await this.browser.close();
process.exit(1);
} finally {