scratch-www/test/integration-legacy/teacher-registration/test_teacher_registration_username_step.js

113 lines
5.1 KiB
JavaScript
Raw Normal View History

2019-07-17 14:56:48 -04:00
/*
* Checks the behavior of first step in the educators registration process
*
* Test cases: https://github.com/LLK/scratch-www/wiki/Testing-Scratch-www#All_Test_Cases_Teacher_Join_Flow
*/
require('chromedriver');
const seleniumWebdriver = require('selenium-webdriver');
const tap = require('tap');
2019-07-17 14:56:48 -04:00
// Set test url through environment variable
const rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
2019-07-17 14:56:48 -04:00
// chrome driver
const driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome())
2019-07-17 14:56:48 -04:00
.build();
tap.plan(5);
tap.tearDown(() => {
2019-07-17 14:56:48 -04:00
driver.quit();
});
tap.beforeEach(() => driver.get(`${rootUrl}/educators/register`));
2019-07-17 14:56:48 -04:00
// an error message should appear for a username less than 3 characters long
// input a username less than 3 characters and look for the validation message
tap.test('checkAtLeastThreeCharacters', t => {
2019-07-17 14:56:48 -04:00
// open scratch in a new instance of the browser
driver.get('https://scratch.mit.edu/educators/register');
const usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
const errorMessage = 'Usernames must be at least 3 characters';
const errorMessageXPath = `//span[@class="help-block validation-message" and contains(text(),"${
errorMessage}")]`;
usernameInput.sendKeys('hi').then(() => {
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(validationMessages => {
2019-07-17 14:56:48 -04:00
t.equal(validationMessages.length, 1);
t.end();
});
});
});
// usernames have to be unique
// input a username that exists and check that an error message appears
tap.test('checkUsernameExistsError', t => {
const usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
const passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
const inputUsername = usernameInput.sendKeys('mres');
const passwordClick = passwordInput.click();
const errorMessage = 'Sorry, that username already exists';
const errorMessageXPath = `//span[@class="help-block validation-message" and contains(text(),"${
errorMessage}")]`;
Promise.all([inputUsername, passwordClick]).then(() => { // eslint-disable-line no-undef
const errorBubble = driver.wait(seleniumWebdriver.until
2019-07-17 14:56:48 -04:00
.elementLocated(seleniumWebdriver.By.xpath(errorMessageXPath)), 10000);
t.notEqual(errorBubble, undefined); // eslint-disable-line no-undefined
t.end();
});
});
// passwords must be at least 6 characters
// find the validation message if the input password is less than 6 characters
tap.test('checkPasswordAtLeastSixCharacters', t => {
const passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
const errorMessage = 'Passwords must be at least six characters';
const errorMessageXPath = `//span[@class="help-block validation-message" and contains(text(),"${
errorMessage}")]`;
passwordInput.sendKeys('hello').then(() => {
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(validationMessages => {
2019-07-17 14:56:48 -04:00
t.equal(validationMessages.length, 1);
t.end();
});
});
});
// password cannot be "password"
// find the validation message if the user inputs "password"
tap.test('checkPasswordNotPassword', t => {
2019-07-17 14:56:48 -04:00
driver.get('https://scratch.mit.edu/educators/register');
const passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
2019-07-17 14:56:48 -04:00
// keeping "password" in messed with the xPath, may need to find a better way
const errorMessage = 'Your password may not be';
const errorMessageXPath = `//span[@class="help-block validation-message" and contains(text(),"${
errorMessage}")]`;
passwordInput.sendKeys('password').then(() => {
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(validationMessages => {
2019-07-17 14:56:48 -04:00
t.equal(validationMessages.length, 1);
t.end();
});
});
});
// the username and password cannot be the same
// find the validation message if the username and password match
tap.test('checkPasswordNotUsername', t => {
2019-07-17 14:56:48 -04:00
driver.get('https://scratch.mit.edu/educators/register');
const passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
const usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
const errorMessage = 'Your password may not be your username';
const errorMessageXPath = `//span[@class="help-block validation-message" and contains(text(),"${
errorMessage}")]`;
const usernamePromise = usernameInput.sendKeys('educator');
const passwordPromise = passwordInput.sendKeys('educator');
2019-07-17 14:56:48 -04:00
// wait for both inputs to have the same text, and check for validation message
Promise.all([usernamePromise, passwordPromise]).then(() => { // eslint-disable-line no-undef
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(validationMessages => {
2019-07-17 14:56:48 -04:00
// there should be only one validation message
t.equal(validationMessages.length, 1);
t.end();
});
});
});