From fe2ce902e609ec63464737ef3ea18f94c3fd6c43 Mon Sep 17 00:00:00 2001 From: cwillaim Date: Wed, 21 Dec 2016 16:54:51 -0500 Subject: [PATCH] Update tests to use an environment value for the url, and consolidate the slide advancement functions. Update utils with better xpath for error messages --- .../teacher_registration_utils.js | 2 +- .../test_teacher_registration_address_step.js | 34 ++++------------ ..._teacher_registration_demographics_step.js | 7 +++- .../test_teacher_registration_name_step.js | 21 ++++------ ..._teacher_registration_organization_step.js | 10 ++--- .../test_teacher_registration_phone_step.js | 23 ++++------- ...test_teacher_registration_username_step.js | 5 ++- ...st_teacher_registration_usescratch_step.js | 40 ++++--------------- 8 files changed, 45 insertions(+), 97 deletions(-) diff --git a/test/integration/teacher-registration/teacher_registration_utils.js b/test/integration/teacher-registration/teacher_registration_utils.js index 8b29c1c1d..424ca4319 100644 --- a/test/integration/teacher-registration/teacher_registration_utils.js +++ b/test/integration/teacher-registration/teacher_registration_utils.js @@ -1,6 +1,6 @@ module.exports.constants = { 'nextStepXpath': '//button[span[contains(text(), "Next Step")]]', - 'generalErrorMessageXpath': '//span[@class="help-block validation-message" and contains(text(),' + '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' diff --git a/test/integration/teacher-registration/test_teacher_registration_address_step.js b/test/integration/teacher-registration/test_teacher_registration_address_step.js index 36d3b623d..2e2361adc 100644 --- a/test/integration/teacher-registration/test_teacher_registration_address_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_address_step.js @@ -11,31 +11,11 @@ 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'; +var rootUrl = process.env.ROOT_URL || 'http://localhost:8333'; //chrome driver var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); -var fillUsernameSlide = function () { - return utils.fillUsernameSlide(driver, seleniumWebdriver); -}; - -var fillDemographicsSlide = function () { - return utils.fillDemographicsSlide(driver, seleniumWebdriver); -}; - -var fillNameSlide = function () { - return utils.fillNameSlide(driver, seleniumWebdriver); -}; - -var fillPhoneSlide = function () { - return utils.fillPhoneSlide(driver, seleniumWebdriver); -}; - -var fillOrganizationSlide = function () { - return utils.fillOrganizationSlide(driver, seleniumWebdriver); -}; - tap.plan(2); tap.tearDown(function () { @@ -43,12 +23,12 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - driver.get('https://scratch.mit.edu/educators/register'); - return fillUsernameSlide() - .then(fillDemographicsSlide) - .then(fillNameSlide) - .then(fillPhoneSlide) - .then(fillOrganizationSlide); + 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 diff --git a/test/integration/teacher-registration/test_teacher_registration_demographics_step.js b/test/integration/teacher-registration/test_teacher_registration_demographics_step.js index f0164ca32..ee176a9fb 100644 --- a/test/integration/teacher-registration/test_teacher_registration_demographics_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_demographics_step.js @@ -10,6 +10,9 @@ 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(); @@ -20,7 +23,7 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - driver.get('https://scratch.mit.edu/educators/register'); + driver.get(rootUrl + '/educators/register'); return utils.fillUsernameSlide(driver, seleniumWebdriver); }); @@ -33,7 +36,7 @@ tap.test('checkOtherGenderInput', function (t) { 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)) + driver.findElements(seleniumWebdriver.By.xpath(constants.generalErrorMessageXpath)) .then(function (validationMessages) { t.equal(validationMessages.length, 1); t.end(); diff --git a/test/integration/teacher-registration/test_teacher_registration_name_step.js b/test/integration/teacher-registration/test_teacher_registration_name_step.js index 13cbc22b6..b30bc5ffe 100644 --- a/test/integration/teacher-registration/test_teacher_registration_name_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_name_step.js @@ -10,17 +10,12 @@ 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(); -var fillUsernameSlide = function () { - return utils.fillUsernameSlide(driver, seleniumWebdriver); -}; - -var fillDemographicsSlide = function () { - return utils.fillDemographicsSlide(driver, seleniumWebdriver); -}; - tap.plan(2); tap.tearDown(function () { @@ -28,16 +23,16 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - driver.get('https://scratch.mit.edu/educators/register'); - return fillUsernameSlide() - .then(fillDemographicsSlide); + 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" and contains(text(),' + + 'span[@class="help-block validation-message"]/span[contains(text(),' + '"This field is required")]'; nextStepButton.click().then(function () { driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)) @@ -52,7 +47,7 @@ tap.test('checkFirstNameRequired', function (t) { 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" and contains(text(),' + + 'span[@class="help-block validation-message"]/span[contains(text(),' + '"This field is required")]'; nextStepButton.click().then(function () { driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)) diff --git a/test/integration/teacher-registration/test_teacher_registration_organization_step.js b/test/integration/teacher-registration/test_teacher_registration_organization_step.js index 8cdf97b7e..01ed6a099 100644 --- a/test/integration/teacher-registration/test_teacher_registration_organization_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_organization_step.js @@ -11,7 +11,7 @@ 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'; +var rootUrl = process.env.ROOT_URL || 'http://localhost:8333'; //chrome driver var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); @@ -23,11 +23,11 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - driver.get('https://scratch.mit.edu/educators/register'); + driver.get(rootUrl + '/educators/register'); return utils.fillUsernameSlide(driver, seleniumWebdriver) - .then(function () { utils.fillDemographicsSlide(driver, seleniumWebdriver); }) - .then(function () { utils.fillNameSlide(driver, seleniumWebdriver); }) - .then(function () { utils.fillPhoneSlide(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) { diff --git a/test/integration/teacher-registration/test_teacher_registration_phone_step.js b/test/integration/teacher-registration/test_teacher_registration_phone_step.js index 460d3f0d5..2456567ac 100644 --- a/test/integration/teacher-registration/test_teacher_registration_phone_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_phone_step.js @@ -9,21 +9,12 @@ 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(); -var fillUsernameSlide = function () { - return utils.fillUsernameSlide(driver, seleniumWebdriver); -}; - -var fillDemographicsSlide = function () { - return utils.fillDemographicsSlide(driver, seleniumWebdriver); -}; - -var fillNameSlide = function () { - return utils.fillNameSlide(driver, seleniumWebdriver); -}; - tap.plan(1); tap.tearDown(function () { @@ -31,10 +22,10 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - driver.get('https://scratch.mit.edu/educators/register'); - return fillUsernameSlide() - .then(fillDemographicsSlide) - .then(fillNameSlide); + 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 diff --git a/test/integration/teacher-registration/test_teacher_registration_username_step.js b/test/integration/teacher-registration/test_teacher_registration_username_step.js index 99366673d..f8fb7e9a8 100644 --- a/test/integration/teacher-registration/test_teacher_registration_username_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_username_step.js @@ -8,6 +8,9 @@ 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(); @@ -18,7 +21,7 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - return driver.get('https://scratch.mit.edu/educators/register'); + return driver.get(rootUrl + '/educators/register'); }); //an error message should appear for a username less than 3 characters long diff --git a/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js b/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js index 511813b21..97235697c 100644 --- a/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js +++ b/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js @@ -11,35 +11,11 @@ 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'; +var rootUrl = process.env.ROOT_URL || 'http://localhost:8333'; //chrome driver var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); -var fillUsernameSlide = function () { - return utils.fillUsernameSlide(driver, seleniumWebdriver); -}; - -var fillDemographicsSlide = function () { - return utils.fillDemographicsSlide(driver, seleniumWebdriver); -}; - -var fillNameSlide = function () { - return utils.fillNameSlide(driver, seleniumWebdriver); -}; - -var fillPhoneSlide = function () { - return utils.fillPhoneSlide(driver, seleniumWebdriver); -}; - -var fillOrganizationSlide = function () { - return utils.fillOrganizationSlide(driver, seleniumWebdriver); -}; - -var fillAddressSlide = function () { - return utils.fillAddressSlide(driver, seleniumWebdriver); -}; - tap.plan(3); tap.tearDown(function () { @@ -47,13 +23,13 @@ tap.tearDown(function () { }); tap.beforeEach(function () { - driver.get('https://scratch.mit.edu/educators/register'); - return fillUsernameSlide() - .then(fillDemographicsSlide) - .then(fillNameSlide) - .then(fillPhoneSlide) - .then(fillOrganizationSlide) - .then(fillAddressSlide); + 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) {