puppeteer: Add run_test method to common.

This method does all error handling and removes ~5-6 lines of try/catch
block across each test file.
This commit is contained in:
Priyank Patel
2020-05-15 15:38:25 +00:00
committed by Tim Abbott
parent 41447a0d5c
commit d0a7540534
3 changed files with 46 additions and 47 deletions

View File

@@ -28,6 +28,18 @@ class CommonUtils {
return page;
}
async run_test(test_function) {
try {
await test_function();
} catch (e) {
console.log(e);
await this.browser.close();
process.exit(1);
} finally {
this.browser.close();
}
}
}
const common = new CommonUtils();

View File

@@ -7,7 +7,6 @@ const organization_name = 'Awesome Organization';
const host = "zulipdev.com:9981";
async function run() {
try {
const page = await common.get_page('http://' + host + '/new/');
// submit the email for realm creation.
@@ -44,12 +43,6 @@ async function run() {
// Check if realm is created and user is logged in by checking if
// element of id `lightbox_overlay` exists.
await page.waitForSelector('#lightbox_overlay'); // if element doesn't exist,timeout error raises
} catch (e) {
console.log(e);
process.exit(1);
} finally {
common.browser.close();
}
}
run();
common.run_test(run);

View File

@@ -24,14 +24,8 @@ async function log_out(page) {
async function run() {
const page = await common.get_page(realm_url + 'login/');
try {
await log_in(page, test_credentials.default_user);
await log_out(page);
} catch (e) {
console.log(e);
process.exit(1);
} finally {
common.browser.close();
}
}
run();
common.run_test(run);