Files
zulip/frontend_tests/puppeteer_tests/01-login.js
Priyank Patel 0b698d1173 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.
2020-05-27 12:50:22 -07:00

32 lines
1.1 KiB
JavaScript

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);
assert(page.url().includes('accounts/login/'));
}
async function login_tests(page) {
await page.goto(realm_url + 'login/');
await log_in(page, test_credentials.default_user);
await log_out(page);
}
common.run_test(login_tests);