mirror of
https://github.com/zulip/zulip.git
synced 2026-07-18 21:04:19 +08:00
puppeteer_tests: Move log_in and log_out functions to common.js.
Since `log_in` and `log_out` functions will also be used in other tests, these are moved to `common.js`.
This commit is contained in:
parent
f91548ec02
commit
d9cc081b2d
@ -1,10 +1,12 @@
|
||||
const path = require('path');
|
||||
const puppeteer = require('puppeteer');
|
||||
const assert = require("assert");
|
||||
|
||||
class CommonUtils {
|
||||
constructor() {
|
||||
this.browser = null;
|
||||
this.screenshot_id = 0;
|
||||
this.realm_url = "http://zulip.zulipdev.com:9981/";
|
||||
}
|
||||
|
||||
async ensure_browser() {
|
||||
@ -44,6 +46,31 @@ class CommonUtils {
|
||||
});
|
||||
}
|
||||
|
||||
async log_in(page, credentials) {
|
||||
console.log("Logging in");
|
||||
await page.goto(this.realm_url + 'login/');
|
||||
assert.equal(this.realm_url + 'login/', page.url());
|
||||
await page.type('#id_username', credentials.username);
|
||||
await page.type('#id_password', credentials.password);
|
||||
await page.$eval('#login_form', form => form.submit());
|
||||
}
|
||||
|
||||
async log_out(page) {
|
||||
await page.goto(this.realm_url);
|
||||
const menu_selector = '#settings-dropdown';
|
||||
const logout_selector = 'a[href="#logout"]';
|
||||
console.log("Loggin out");
|
||||
await page.waitForSelector(menu_selector, {visible: true});
|
||||
await page.click(menu_selector);
|
||||
await page.waitForSelector(logout_selector);
|
||||
await page.click(logout_selector);
|
||||
|
||||
// Wait for a email input in login page so we know login
|
||||
// page is loaded. Then check that we are at the login url.
|
||||
await page.waitForSelector('input[name="username"]');
|
||||
assert(page.url().includes('/login/'));
|
||||
}
|
||||
|
||||
async run_test(test_function) {
|
||||
// Pass a page instance to test so we can take
|
||||
// a screenshot of it when the test fails.
|
||||
|
||||
@ -1,35 +1,9 @@
|
||||
const assert = require("assert");
|
||||
const common = require('../puppeteer_lib/common');
|
||||
const test_credentials = require('../../var/casper/test_credentials.js').test_credentials;
|
||||
const realm_url = "http://zulip.zulipdev.com:9981/";
|
||||
|
||||
async function log_in(page, credentials) {
|
||||
console.log("Logging in");
|
||||
assert.equal(realm_url + 'login/', page.url());
|
||||
await page.type('#id_username', credentials.username);
|
||||
await page.type('#id_password', credentials.password);
|
||||
await page.$eval('#login_form', form => form.submit());
|
||||
}
|
||||
|
||||
async function log_out(page) {
|
||||
await page.goto(realm_url);
|
||||
const menu_selector = '#settings-dropdown';
|
||||
const logout_selector = 'a[href="#logout"]';
|
||||
await page.waitForSelector(menu_selector, {visible: true});
|
||||
await page.click(menu_selector);
|
||||
await page.waitForSelector(logout_selector);
|
||||
await page.click(logout_selector);
|
||||
|
||||
// Wait for a email input in login page so we know login
|
||||
// page is loaded. Then check that we are at the login url.
|
||||
await page.waitForSelector('input[name="username"]');
|
||||
assert(page.url().includes('/login/'));
|
||||
}
|
||||
|
||||
async function login_tests(page) {
|
||||
await page.goto(realm_url + 'login/');
|
||||
await log_in(page, test_credentials.default_user);
|
||||
await log_out(page);
|
||||
await common.log_in(page, test_credentials.default_user);
|
||||
await common.log_out(page);
|
||||
}
|
||||
|
||||
common.run_test(login_tests);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user