2016-12-08 17:45:17 -05: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');
|
|
|
|
var seleniumWebdriver = require('selenium-webdriver');
|
|
|
|
var tap = require('tap');
|
|
|
|
|
2018-01-30 09:53:25 -05:00
|
|
|
//Set test url through environment variable
|
2016-12-21 16:54:51 -05:00
|
|
|
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
|
|
|
|
2018-01-30 09:53:25 -05:00
|
|
|
//chrome driver
|
|
|
|
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
2016-12-08 17:45:17 -05:00
|
|
|
|
|
|
|
tap.plan(5);
|
|
|
|
|
|
|
|
tap.tearDown(function () {
|
|
|
|
driver.quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.beforeEach(function () {
|
2016-12-21 16:54:51 -05:00
|
|
|
return driver.get(rootUrl + '/educators/register');
|
2016-12-08 17:45:17 -05:00
|
|
|
});
|
|
|
|
|
2018-01-30 09:53:25 -05: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
|
2016-12-08 17:45:17 -05:00
|
|
|
tap.test('checkAtLeastThreeCharacters', function (t) {
|
2018-01-30 09:53:25 -05:00
|
|
|
//open scratch in a new instance of the browser
|
2016-12-08 17:45:17 -05:00
|
|
|
driver.get('https://scratch.mit.edu/educators/register');
|
|
|
|
var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
|
|
|
|
var errorMessage = 'Usernames must be at least 3 characters';
|
2018-01-30 09:53:25 -05:00
|
|
|
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
|
|
|
+ errorMessage + '")]';
|
2016-12-08 17:45:17 -05:00
|
|
|
usernameInput.sendKeys('hi').then(function () {
|
|
|
|
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
|
|
|
t.equal(validationMessages.length, 1);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 09:53:25 -05:00
|
|
|
//usernames have to be unique
|
|
|
|
//input a username that exists and check that an error message appears
|
2016-12-08 17:45:17 -05:00
|
|
|
tap.test('checkUsernameExistsError', function (t) {
|
|
|
|
var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
|
|
|
|
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
|
|
|
var inputUsername = usernameInput.sendKeys('mres');
|
|
|
|
var passwordClick = passwordInput.click();
|
|
|
|
var errorMessage = 'Sorry, that username already exists';
|
2018-01-30 09:53:25 -05:00
|
|
|
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
|
|
|
+ errorMessage + '")]';
|
|
|
|
Promise.all([inputUsername, passwordClick]).then(function () {
|
|
|
|
var errorBubble = driver.wait(seleniumWebdriver.until.
|
|
|
|
elementLocated(seleniumWebdriver.By.xpath(errorMessageXPath)), 10000);
|
|
|
|
t.notEqual(errorBubble, undefined);
|
2016-12-08 17:45:17 -05:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 09:53:25 -05:00
|
|
|
//passwords must be at least 6 characters
|
|
|
|
//find the validation message if the input password is less than 6 characters
|
2016-12-08 17:45:17 -05:00
|
|
|
tap.test('checkPasswordAtLeastSixCharacters', function (t) {
|
|
|
|
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
|
|
|
var errorMessage = 'Passwords must be at least six characters';
|
2018-01-30 09:53:25 -05:00
|
|
|
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
|
|
|
+ errorMessage + '")]';
|
2016-12-08 17:45:17 -05:00
|
|
|
passwordInput.sendKeys('hello').then(function () {
|
|
|
|
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
|
|
|
t.equal(validationMessages.length, 1);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 09:53:25 -05:00
|
|
|
//password cannot be "password"
|
|
|
|
//find the validation message if the user inputs "password"
|
2016-12-08 17:45:17 -05:00
|
|
|
tap.test('checkPasswordNotPassword', function (t) {
|
|
|
|
driver.get('https://scratch.mit.edu/educators/register');
|
|
|
|
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
2018-01-30 09:53:25 -05:00
|
|
|
//keeping "password" in messed with the xPath, may need to find a better way
|
2016-12-08 17:45:17 -05:00
|
|
|
var errorMessage = 'Your password may not be';
|
2018-01-30 09:53:25 -05:00
|
|
|
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
|
|
|
+ errorMessage + '")]';
|
2016-12-08 17:45:17 -05:00
|
|
|
passwordInput.sendKeys('password').then(function () {
|
|
|
|
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
|
|
|
t.equal(validationMessages.length, 1);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 09:53:25 -05:00
|
|
|
//the username and password cannot be the same
|
|
|
|
//find the validation message if the username and password match
|
2016-12-08 17:45:17 -05:00
|
|
|
tap.test('checkPasswordNotUsername', function (t) {
|
|
|
|
driver.get('https://scratch.mit.edu/educators/register');
|
|
|
|
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
|
|
|
var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
|
|
|
|
var errorMessage = 'Your password may not be your username';
|
2018-01-30 09:53:25 -05:00
|
|
|
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
|
|
|
+ errorMessage + '")]';
|
2016-12-08 17:45:17 -05:00
|
|
|
var usernamePromise = usernameInput.sendKeys('educator');
|
|
|
|
var passwordPromise = passwordInput.sendKeys('educator');
|
2018-01-30 09:53:25 -05:00
|
|
|
//wait for both inputs to have the same text, and check for validation message
|
|
|
|
Promise.all([usernamePromise, passwordPromise]).then(function () {
|
2016-12-08 17:45:17 -05:00
|
|
|
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
2018-01-30 09:53:25 -05:00
|
|
|
//there should be only one validation message
|
2016-12-08 17:45:17 -05:00
|
|
|
t.equal(validationMessages.length, 1);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-01-30 09:53:25 -05:00
|
|
|
|