mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
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:
committed by
Tim Abbott
parent
41447a0d5c
commit
d0a7540534
@@ -28,6 +28,18 @@ class CommonUtils {
|
|||||||
|
|
||||||
return page;
|
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();
|
const common = new CommonUtils();
|
||||||
|
|||||||
@@ -7,49 +7,42 @@ const organization_name = 'Awesome Organization';
|
|||||||
const host = "zulipdev.com:9981";
|
const host = "zulipdev.com:9981";
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
const page = await common.get_page('http://' + host + '/new/');
|
||||||
const page = await common.get_page('http://' + host + '/new/');
|
|
||||||
|
|
||||||
// submit the email for realm creation.
|
// submit the email for realm creation.
|
||||||
await page.waitForSelector('#email');
|
await page.waitForSelector('#email');
|
||||||
await page.type('#email', email);
|
await page.type('#email', email);
|
||||||
await page.$eval('#send_confirm', form => form.submit());
|
await page.$eval('#send_confirm', form => form.submit());
|
||||||
|
|
||||||
// Make sure onfirmation email is sent.
|
// Make sure onfirmation email is sent.
|
||||||
assert(page.url().includes('/accounts/new/send_confirm/' + email));
|
assert(page.url().includes('/accounts/new/send_confirm/' + email));
|
||||||
|
|
||||||
// Special endpoint enabled only during tests for extracting confirmation key
|
// Special endpoint enabled only during tests for extracting confirmation key
|
||||||
await page.goto('http://' + host + '/confirmation_key/');
|
await page.goto('http://' + host + '/confirmation_key/');
|
||||||
|
|
||||||
// Open the confirmation URL
|
// Open the confirmation URL
|
||||||
const page_content = await page.evaluate(() => document.querySelector('body').innerText);
|
const page_content = await page.evaluate(() => document.querySelector('body').innerText);
|
||||||
const confirmation_key = await JSON.parse(page_content).confirmation_key;
|
const confirmation_key = await JSON.parse(page_content).confirmation_key;
|
||||||
const confirmation_url = 'http://' + host + '/accounts/do_confirm/' + confirmation_key;
|
const confirmation_url = 'http://' + host + '/accounts/do_confirm/' + confirmation_key;
|
||||||
await page.goto(confirmation_url);
|
await page.goto(confirmation_url);
|
||||||
|
|
||||||
// Make sure the realm creation page is loaded correctly by
|
// Make sure the realm creation page is loaded correctly by
|
||||||
// checking the text in <p> tag under pitch class is as expected.
|
// checking the text in <p> tag under pitch class is as expected.
|
||||||
await page.waitForSelector('.pitch');
|
await page.waitForSelector('.pitch');
|
||||||
const text_in_pitch = await page.evaluate(() => document.querySelector('.pitch p').innerText);
|
const text_in_pitch = await page.evaluate(() => document.querySelector('.pitch p').innerText);
|
||||||
assert(text_in_pitch === "We just need you to do one last thing.");
|
assert(text_in_pitch === "We just need you to do one last thing.");
|
||||||
|
|
||||||
// fill the form.
|
// fill the form.
|
||||||
await page.type('#id_team_name', organization_name);
|
await page.type('#id_team_name', organization_name);
|
||||||
await page.type('#id_full_name', 'Alice');
|
await page.type('#id_full_name', 'Alice');
|
||||||
await page.type('#id_team_subdomain', subdomain);
|
await page.type('#id_team_subdomain', subdomain);
|
||||||
await page.type('#id_password', 'passwordwhichisnotreallycomplex');
|
await page.type('#id_password', 'passwordwhichisnotreallycomplex');
|
||||||
await page.click('#id_terms');
|
await page.click('#id_terms');
|
||||||
await page.$eval('#registration', form => form.submit());
|
await page.$eval('#registration', form => form.submit());
|
||||||
|
|
||||||
// Check if realm is created and user is logged in by checking if
|
// Check if realm is created and user is logged in by checking if
|
||||||
// element of id `lightbox_overlay` exists.
|
// element of id `lightbox_overlay` exists.
|
||||||
await page.waitForSelector('#lightbox_overlay'); // if element doesn't exist,timeout error raises
|
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);
|
||||||
|
|||||||
@@ -24,14 +24,8 @@ async function log_out(page) {
|
|||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const page = await common.get_page(realm_url + 'login/');
|
const page = await common.get_page(realm_url + 'login/');
|
||||||
try {
|
await log_in(page, test_credentials.default_user);
|
||||||
await log_in(page, test_credentials.default_user);
|
await log_out(page);
|
||||||
await log_out(page);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
process.exit(1);
|
|
||||||
} finally {
|
|
||||||
common.browser.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
run();
|
|
||||||
|
common.run_test(run);
|
||||||
|
|||||||
Reference in New Issue
Block a user