diff --git a/test/integration/test_educators_registration_demographics.js b/test/integration/test_educators_registration_demographics.js new file mode 100644 index 000000000..6f3b56f8b --- /dev/null +++ b/test/integration/test_educators_registration_demographics.js @@ -0,0 +1,78 @@ +/* + * 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'); + +//chrome driver +var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); + +var fillUsernameSlide = function () { + var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password')); + var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username')); + var usernamePromise = usernameInput.sendKeys('ladybug'); + var passwordPromise = passwordInput.sendKeys('educators'); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath('//button[span[contains(text(),' + + '"Next Step")]]')); + return Promise.all([usernamePromise, passwordPromise]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('demographics-step'))); + }); + }); +}; + +tap.plan(2); + +tap.tearDown(function () { + driver.quit(); +}); + +tap.beforeEach(function () { + driver.get('https://scratch.mit.edu/educators/register'); + return fillUsernameSlide(); +}); + +//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('//button[span[contains(text(),' + + '"Next Step")]]')); + var errorMessage = 'This field is required'; + var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"' + + errorMessage + '")]'; + 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(errorMessageXPath)) + .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('//button[span[contains(text(),' + + '"Next Step")]]')); + var errorMessage = 'This field is required'; + var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"' + + errorMessage + '")]'; + driver.findElement(seleniumWebdriver.By.xpath('//select[@name="user.country"]/option[2]')).click(); + nextStepButton.click().then(function () { + driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)) + .then(function (validationMessages) { + t.equal(validationMessages.length, 1); + t.end(); + }); + }); +}); + diff --git a/test/integration/test_educators_registration_name_step.js b/test/integration/test_educators_registration_name_step.js new file mode 100644 index 000000000..35abb50ab --- /dev/null +++ b/test/integration/test_educators_registration_name_step.js @@ -0,0 +1,69 @@ +/* + * 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'); + +//chrome driver +var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); + +var fillUsernameSlide = function () { + var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password')); + var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username')); + var usernamePromise = usernameInput.sendKeys('ladybug'); + var passwordPromise = passwordInput.sendKeys('educators'); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath('//button[span[contains(text(),' + + '"Next Step")]]')); + return Promise.all([usernamePromise, passwordPromise]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('demographics-step'))); + }); + }); +}; + +var fillDemographicsSlide = function () { + 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[2]')).click(); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath('//button[span[contains(text(),' + + '"Next Step")]]')); + return Promise.all([clickMaleInput, selectCountry]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('name-step'))); + }); + }); +}; + +tap.plan(1); + +tap.tearDown(function () { + driver.quit(); +}); + +tap.beforeEach(function () { + driver.get('https://scratch.mit.edu/educators/register'); + return fillUsernameSlide().then(fillDemographicsSlide); +}); + +//attempts to advance the slide without inputting either name, checks that both give the correct error +tap.test('checkBothNamesRequired', function (t) { + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath('//button[span[contains(text(),' + + '"Next Step")]]')); + var errorMessage = 'This field is required'; + var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"' + + errorMessage + '")]'; + nextStepButton.click().then(function () { + driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)) + .then(function (validationMessages) { + t.equal(validationMessages.length, 2); + t.end(); + }); + }); +}); + diff --git a/test/integration/test_educators_registration_phone_step.js b/test/integration/test_educators_registration_phone_step.js new file mode 100644 index 000000000..7a6a3ff2c --- /dev/null +++ b/test/integration/test_educators_registration_phone_step.js @@ -0,0 +1,83 @@ +/* + * 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'); + +//chrome driver +var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); + +var fillUsernameSlide = function () { + var passwordInput = driver.findElement(seleniumWebdriver.By.name('user.password')); + var usernameInput = driver.findElement(seleniumWebdriver.By.name('user.username')); + var usernamePromise = usernameInput.sendKeys('ladybug'); + var passwordPromise = passwordInput.sendKeys('educators'); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath('//button[span[contains(text(),' + + '"Next Step")]]')); + return Promise.all([usernamePromise, passwordPromise]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('demographics-step'))); + }); + }); +}; + +var fillDemographicsSlide = function () { + 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[2]')).click(); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath('//button[span[contains(text(),' + + '"Next Step")]]')); + return Promise.all([clickMaleInput, selectCountry]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('name-step'))); + }); + }); +}; + +var fillNameSlide = function () { + 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('//button[span[contains(text(),' + + '"Next Step")]]')); + return Promise.all([firstNamePromise, lastNamePromise]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('phone-step'))); + }); + }); +}; + +tap.plan(1); + +tap.tearDown(function () { + driver.quit(); +}); + +tap.beforeEach(function () { + driver.get('https://scratch.mit.edu/educators/register'); + return fillUsernameSlide() + .then(fillDemographicsSlide) + .then(fillNameSlide); +}); + +//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(); + }); + }); +}); + diff --git a/test/integration/test_educators_registration_username_step.js b/test/integration/test_educators_registration_username_step.js new file mode 100644 index 000000000..99366673d --- /dev/null +++ b/test/integration/test_educators_registration_username_step.js @@ -0,0 +1,111 @@ +/* +* 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'); + +//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('https://scratch.mit.edu/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(); + }); + }); +}); +