mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-14 15:09:59 -04:00
Merge pull request #1139 from mewtaylor/cwillaim-feature/teacher-registration-flow-tests
Tests for the teacher registration flow
This commit is contained in:
commit
4967f315e8
8 changed files with 595 additions and 0 deletions
|
@ -0,0 +1,97 @@
|
|||
module.exports.constants = {
|
||||
'nextStepXpath': '//button[span[contains(text(), "Next Step")]]',
|
||||
'generalErrorMessageXpath': '//span[@class="help-block validation-message"]/span[contains(text(),'
|
||||
+ '"This field is required")]',
|
||||
'loremIpsumTextLong': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur viverra'
|
||||
+ 'nec mauris efficitur tincidunt. Vestibulum ut diam odio. Cum sociis natoque penatibus et magnis dis'
|
||||
+ 'parturient montes, nascetur ridiculus mus. Morbi non enim dolor. Vestibulum at enim vestibulum, ullamcorper'
|
||||
+ 'Duis eget quam pharetra, ultricies est eu, pharetra nisi. In tempor cursus nisi, non sagittis quam gravida.'
|
||||
};
|
||||
|
||||
module.exports.fillUsernameSlide = function (driver, seleniumWebdriver) {
|
||||
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
||||
var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username'));
|
||||
var usernamePromise = usernameInput.sendKeys('clipspringer');
|
||||
var passwordPromise = passwordInput.sendKeys('educators');
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath));
|
||||
return Promise.all([usernamePromise, passwordPromise]).then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.wait(seleniumWebdriver.until
|
||||
.elementLocated(seleniumWebdriver.By.className('demographics-step')));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fillDemographicsSlide = function (driver, seleniumWebdriver) {
|
||||
var clickMaleInput = driver.findElement(seleniumWebdriver.By.xpath('//input[@value="male"' +
|
||||
'and @type="radio"]')).click();
|
||||
var selectCountry = driver.findElement(seleniumWebdriver.By.xpath('//select[@name="user.country"]' +
|
||||
'/option[@value="us"]')).click();
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath));
|
||||
return Promise.all([clickMaleInput, selectCountry]).then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.wait(seleniumWebdriver.until
|
||||
.elementLocated(seleniumWebdriver.By.className('name-step')));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fillNameSlide = function (driver, seleniumWebdriver) {
|
||||
var firstNamePromise = driver.findElement(seleniumWebdriver.By.name('user.name.first')).sendKeys('first');
|
||||
var lastNamePromise = driver.findElement(seleniumWebdriver.By.name('user.name.last')).sendKeys('surname');
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath));
|
||||
return Promise.all([firstNamePromise, lastNamePromise]).then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.wait(seleniumWebdriver.until
|
||||
.elementLocated(seleniumWebdriver.By.className('phone-step')));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fillPhoneSlide = function (driver, seleniumWebdriver) {
|
||||
var phoneInput = driver.findElement(seleniumWebdriver.By.xpath('//input[@type="tel"]'));
|
||||
var consentCheckbox = driver.findElement(seleniumWebdriver.By.name('phoneConsent'));
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath));
|
||||
var phoneNumberPromise = phoneInput.sendKeys('6172535960');
|
||||
var consentPromise = consentCheckbox.click();
|
||||
return Promise.all([phoneNumberPromise, consentPromise]).then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.wait(seleniumWebdriver.until
|
||||
.elementLocated(seleniumWebdriver.By.className('organization-step')));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fillOrganizationSlide = function (driver, seleniumWebdriver) {
|
||||
var organizationInput = driver.findElement(seleniumWebdriver.By.name('organization.name'));
|
||||
var titleInput = driver.findElement(seleniumWebdriver.By.name('organization.title'));
|
||||
var typeCheckbox = driver.findElement(seleniumWebdriver.By.xpath('//input[@type="checkbox" and @value="3"]'));
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath));
|
||||
var organizationPromise = organizationInput.sendKeys('MIT Media Lab');
|
||||
var titlePromise = titleInput.sendKeys('Software Developer');
|
||||
var typePromise = typeCheckbox.click();
|
||||
return Promise.all([organizationPromise, titlePromise, typePromise]).then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.wait(seleniumWebdriver.until
|
||||
.elementLocated(seleniumWebdriver.By.className('address-step')));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.fillAddressSlide = function (driver, seleniumWebdriver) {
|
||||
var addressInput = driver.findElement(seleniumWebdriver.By.name('address.line1'));
|
||||
var cityInput = driver.findElement(seleniumWebdriver.By.name('address.city'));
|
||||
var zipCodeInput = driver.findElement(seleniumWebdriver.By.name('address.zip'));
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath));
|
||||
var addressPromise = addressInput.sendKeys('77 Massachusetts Avenue, E14/E15');
|
||||
var cityPromise = cityInput.sendKeys('Cambridge');
|
||||
var statePromise = driver.findElement(seleniumWebdriver.By.xpath('//select[@name="address.state"]' +
|
||||
'/option[@value="us-ma"]')).click();
|
||||
var zipPromise = zipCodeInput.sendKeys('02139');
|
||||
return Promise.all([addressPromise, cityPromise, statePromise, zipPromise]).then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.wait(seleniumWebdriver.until
|
||||
.elementLocated(seleniumWebdriver.By.className('usescratch-step')));
|
||||
});
|
||||
});
|
||||
};
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Checks the behavior of the address 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');
|
||||
|
||||
var utils = require('./teacher_registration_utils.js');
|
||||
var constants = utils.constants;
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(2);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
driver.get(rootUrl + '/educators/register');
|
||||
return utils.fillUsernameSlide(driver, seleniumWebdriver)
|
||||
.then(utils.fillDemographicsSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillNameSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillPhoneSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillOrganizationSlide.bind(this, driver, seleniumWebdriver));
|
||||
});
|
||||
|
||||
//Selects Vatican City as the country, and checks that the state dropdown disappears
|
||||
tap.test('checkStateDropdownOnlyPresentWhenNeeded', function (t) {
|
||||
driver.findElement(seleniumWebdriver.By.xpath('//select[@name="address.country"]' +
|
||||
'/option[@value="va"]')).click() //select Vatican City as the country
|
||||
.then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.name('address.state'))
|
||||
.then(function (stateDropdown) {
|
||||
t.equal(stateDropdown.length, 0);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('checkZipCodeRequired', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//input[@name="address.zip"]/following-sibling::'
|
||||
+ 'span[@class="help-block validation-message"]/span[contains(text(),'
|
||||
+ '"This field is required")]';
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Checks the behavior of demographics 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');
|
||||
|
||||
var utils = require('./teacher_registration_utils.js');
|
||||
var constants = utils.constants;
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(2);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
driver.get(rootUrl + '/educators/register');
|
||||
return utils.fillUsernameSlide(driver, seleniumWebdriver);
|
||||
});
|
||||
|
||||
//if the user selects the other gender option, they must input a gender
|
||||
//selects the other gender option and attempt to advance the slide
|
||||
tap.test('checkOtherGenderInput', function (t) {
|
||||
var otherGenderRadio = driver.findElement(seleniumWebdriver.By.xpath('//input[@value="other"' +
|
||||
'and @type="radio"]'));
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
driver.findElement(seleniumWebdriver.By.xpath('//select[@name="user.country"]/option[2]')).click();
|
||||
otherGenderRadio.click().then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(constants.generalErrorMessageXpath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//the user must select a gender
|
||||
//tries to advance the slide without selecting a gender
|
||||
tap.test('checkNoGenderInput', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
driver.findElement(seleniumWebdriver.By.xpath('//select[@name="user.country"]/option[2]')).click();
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(constants.generalErrorMessageXpath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Checks the behavior of the name 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');
|
||||
|
||||
var utils = require('./teacher_registration_utils.js');
|
||||
var constants = utils.constants;
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(2);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
driver.get(rootUrl + '/educators/register');
|
||||
return utils.fillUsernameSlide(driver, seleniumWebdriver)
|
||||
.then(utils.fillDemographicsSlide.bind(this, driver, seleniumWebdriver));
|
||||
});
|
||||
|
||||
//attempts to advance the slide without inputting either name, checks that both give the correct error
|
||||
tap.test('checkFirstNameRequired', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//input[@name="user.name.first"]/following-sibling::'
|
||||
+ 'span[@class="help-block validation-message"]/span[contains(text(),'
|
||||
+ '"This field is required")]';
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//attempts to advance the slide without inputting either name, checks that both give the correct error
|
||||
tap.test('checkLastNameRequired', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//input[@name="user.name.last"]/following-sibling::'
|
||||
+ 'span[@class="help-block validation-message"]/span[contains(text(),'
|
||||
+ '"This field is required")]';
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Checks the behavior of the organization 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');
|
||||
|
||||
var utils = require('./teacher_registration_utils.js');
|
||||
var constants = utils.constants;
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(4);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
driver.get(rootUrl + '/educators/register');
|
||||
return utils.fillUsernameSlide(driver, seleniumWebdriver)
|
||||
.then(utils.fillDemographicsSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillNameSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillPhoneSlide.bind(this, driver, seleniumWebdriver));
|
||||
});
|
||||
|
||||
tap.test('otherFieldRequiredIfChecked', function (t) {
|
||||
var otherCheckbox = driver.findElement(seleniumWebdriver.By.xpath('//input[@type="checkbox" and @value="8"]'));
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//div[@class="other-input"]' + constants.generalErrorMessageXpath;
|
||||
otherCheckbox.click().then(function () {
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('checkOrganizationFieldRequired', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//input[@name="organization.name"]/following-sibling::'
|
||||
+ 'span[@class="help-block validation-message"]/span[contains(text(),'
|
||||
+ '"This field is required")]';
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('checkRoleFieldRequired', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//input[@name="organization.title"]/following-sibling::'
|
||||
+ 'span[@class="help-block validation-message"]/span[contains(text(),'
|
||||
+ '"This field is required")]';
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('checkOrganizationTypeRequired', function (t) {
|
||||
var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath));
|
||||
var errorMessageXPath = '//div[@class="checkbox"]/following-sibling::'
|
||||
+ 'span[@class="help-block validation-message" and contains(text(),'
|
||||
+ '"This field is required")]';
|
||||
nextStepButton.click().then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Checks the behavior of the phone number 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');
|
||||
|
||||
var utils = require('./teacher_registration_utils.js');
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(1);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
driver.get(rootUrl + '/educators/register');
|
||||
return utils.fillUsernameSlide(driver, seleniumWebdriver)
|
||||
.then(utils.fillDemographicsSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillNameSlide.bind(this, driver, seleniumWebdriver));
|
||||
});
|
||||
|
||||
//inputs an invalid phone number and checks that the correct error message appears
|
||||
tap.test('validatePhoneNumber', function (t) {
|
||||
var phoneInput = driver.findElement(seleniumWebdriver.By.xpath('//input[@type="tel"]'));
|
||||
var errorMessage = 'Please enter a valid phone number';
|
||||
var errorMessageXPath = '//span[@class="help-block validation-message"]/span[contains(text(),"'
|
||||
+ errorMessage + '")]';
|
||||
phoneInput.sendKeys(1234567890).then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath))
|
||||
.then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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');
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(5);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
return driver.get(rootUrl + '/educators/register');
|
||||
});
|
||||
|
||||
//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', function (t) {
|
||||
//open scratch in a new instance of the browser
|
||||
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';
|
||||
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
||||
+ errorMessage + '")]';
|
||||
usernameInput.sendKeys('hi').then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
||||
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', 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';
|
||||
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);
|
||||
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', function (t) {
|
||||
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
||||
var errorMessage = 'Passwords must be at least six characters';
|
||||
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
||||
+ errorMessage + '")]';
|
||||
passwordInput.sendKeys('hello').then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//password cannot be "password"
|
||||
//find the validation message if the user inputs "password"
|
||||
tap.test('checkPasswordNotPassword', function (t) {
|
||||
driver.get('https://scratch.mit.edu/educators/register');
|
||||
var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password'));
|
||||
//keeping "password" in messed with the xPath, may need to find a better way
|
||||
var errorMessage = 'Your password may not be';
|
||||
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
||||
+ errorMessage + '")]';
|
||||
passwordInput.sendKeys('password').then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
||||
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', 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';
|
||||
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
||||
+ errorMessage + '")]';
|
||||
var usernamePromise = usernameInput.sendKeys('educator');
|
||||
var passwordPromise = passwordInput.sendKeys('educator');
|
||||
//wait for both inputs to have the same text, and check for validation message
|
||||
Promise.all([usernamePromise, passwordPromise]).then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
||||
//there should be only one validation message
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Checks the behavior of the 'use scratch' 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');
|
||||
|
||||
var utils = require('./teacher_registration_utils.js');
|
||||
var constants = utils.constants;
|
||||
|
||||
//Set test url through environment variable
|
||||
var rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
||||
|
||||
//chrome driver
|
||||
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
||||
|
||||
tap.plan(3);
|
||||
|
||||
tap.tearDown(function () {
|
||||
driver.quit();
|
||||
});
|
||||
|
||||
tap.beforeEach(function () {
|
||||
driver.get(rootUrl + '/educators/register');
|
||||
return utils.fillUsernameSlide(driver, seleniumWebdriver)
|
||||
.then(utils.fillDemographicsSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillNameSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillPhoneSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillOrganizationSlide.bind(this, driver, seleniumWebdriver))
|
||||
.then(utils.fillAddressSlide.bind(this, driver, seleniumWebdriver));
|
||||
});
|
||||
|
||||
tap.test('checkCharacterCountIsCorrect', function (t) {
|
||||
var textarea = driver.findElement(seleniumWebdriver.By.name('useScratch'));
|
||||
var charCount = driver.findElement(seleniumWebdriver.By.xpath('//p[@class="char-count"]'));
|
||||
textarea.sendKeys('hello').then(function () {
|
||||
charCount.getText().then(function (charCountText) {
|
||||
t.equal(charCountText, '5/300');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//Inputs more than 300 characters and checks that the char count gets the class 'overmax'
|
||||
//which turns the text orange
|
||||
tap.test('checkCharacterCountTurnsOrangeWhenTooLong', function (t) {
|
||||
var textarea = driver.findElement(seleniumWebdriver.By.name('useScratch'));
|
||||
var charCount = driver.findElement(seleniumWebdriver.By.xpath('//p[@class="char-count"]'));
|
||||
textarea.sendKeys(constants.loremIpsumTextLong).then(function () {
|
||||
charCount.getAttribute('class').then(function (charCountClasses) {
|
||||
t.ok(charCountClasses.includes('overmax'));
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('checkCharacterCountErrorAppersWhenTooLong', function (t) {
|
||||
var textarea = driver.findElement(seleniumWebdriver.By.name('useScratch'));
|
||||
var errorMessage = 'Description must be at most 300 characters';
|
||||
var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"'
|
||||
+ errorMessage + '")]';
|
||||
textarea.sendKeys(constants.loremIpsumTextLong).then(function () {
|
||||
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) {
|
||||
t.equal(validationMessages.length, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue