From e7f57122c220e8422196006f09fda5ed5f710ba5 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Thu, 17 May 2018 11:33:21 -0400 Subject: [PATCH 1/2] Make Selenium Helper function to click element by CSS --- test/integration/selenium-helpers.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/integration/selenium-helpers.js b/test/integration/selenium-helpers.js index 82a3abe58..faf658ec9 100644 --- a/test/integration/selenium-helpers.js +++ b/test/integration/selenium-helpers.js @@ -30,6 +30,10 @@ const findByCss = (css) => { return driver.wait(until.elementLocated(By.css(css), 1000 * 5)); }; +const clickCss = (css) => { + return findByCss(css).then(el => el.click()); +}; + const getLogs = (whitelist) => { return driver.manage() .logs() @@ -65,5 +69,6 @@ module.exports = { findText, clickButton, findByCss, + clickCss, getLogs }; From 86e9549ceea51f9842515ec4283260b3c03e7669 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Thu, 17 May 2018 11:52:05 -0400 Subject: [PATCH 2/2] Make all Selenium tests of login-failures work and use css to select elements. --- .../smoke-testing/test-login-failures.js | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/test/integration/smoke-testing/test-login-failures.js b/test/integration/smoke-testing/test-login-failures.js index ea7b9a78d..fca6c9c01 100644 --- a/test/integration/smoke-testing/test-login-failures.js +++ b/test/integration/smoke-testing/test-login-failures.js @@ -1,10 +1,8 @@ const { - clickText, - findByXpath, - clickButton, driver, - until, - By + findByCss, + clickCss, + until } = require('../selenium-helpers.js'); var username = process.env.SMOKE_USERNAME; @@ -31,17 +29,17 @@ test('Trying to sign in with no password using scratchr2 navbar', t => { var nonsenseusername = Math.random().toString(36) .replace(/[^a-z]+/g, '') .substr(0, 5); - clickText('Sign in') - .then(() => findByXpath('//input[@id="login_dropdown_username"]')) + clickCss('.dropdown-toggle') + .then(() => findByCss('form#login input#login_dropdown_username')) .then((element) => element.sendKeys(nonsenseusername)) - .then(() => clickButton('Sign in')) - .then(() => driver.wait(until - .elementLocated(By.xpath('//form[@id="login"]/button[@type="submit"]')))) - .then(() => driver.wait(until - .elementLocated(By.xpath('//form[@id="login"]/div[@class="error"]')))) - .then(() => findByXpath('//form/div[@class="error"]')) + .then(() => clickCss('form#login button')) + .then(() => findByCss('form#login .error')) + .then((element) => { + driver.wait(until.elementIsVisible(element)); + return element; + }) .then((element) => element.getText()) - .then((text) => t.match(text, 'This field is required.', + .then((text) => t.match(text, 'This field is required', '"This field is required" error should be displayed')) .then(() => t.end()); }); @@ -50,17 +48,17 @@ test('Trying to sign in with the wrong username using scratchr2 navbar', t => { var nonsenseusername = Math.random().toString(36) .replace(/[^a-z]+/g, '') .substr(0, 5); - clickText('Sign in') - .then(() => findByXpath('//input[@id="login_dropdown_username"]')) + clickCss('.dropdown-toggle') + .then(() => findByCss('form#login input#login_dropdown_username')) .then((element) => element.sendKeys(nonsenseusername)) - .then(() => findByXpath('//input[@name="password"]')) + .then(() => findByCss('form#login input.wide.password')) .then((element) => element.sendKeys(password)) - .then(() => clickButton('Sign in')) - .then(() => driver.wait(until - .elementLocated(By.xpath('//form[@id="login"]/button[@type="submit"]')))) - .then(() => driver.wait(until - .elementLocated(By.xpath('//form[@id="login"]/div[@class="error"]')))) - .then(() => findByXpath('//form/div[@class="error"]')) + .then(() => clickCss('form#login button')) + .then(() => findByCss('form#login .error')) + .then((element) => { + driver.wait(until.elementIsVisible(element)); + return element; + }) .then((element) => element.getText()) .then((text) => t.match(text, 'Incorrect username or password.', '"Incorrect username or password" error should be displayed')) @@ -68,17 +66,17 @@ test('Trying to sign in with the wrong username using scratchr2 navbar', t => { }); test('Trying to sign in with the wrong password using scratchr2 navbar', t => { - clickText('Sign in') - .then(() => findByXpath('//input[@id="login_dropdown_username"]')) + clickCss('.dropdown-toggle') + .then(() => findByCss('form#login input#login_dropdown_username')) .then((element) => element.sendKeys(username)) - .then(() => findByXpath('//input[@name="password"]')) + .then(() => findByCss('form#login input.wide.password')) .then((element) => element.sendKeys('nonsensepassword')) - .then(() => clickButton('Sign in')) - .then(() => driver.wait(until - .elementLocated(By.xpath('//form[@id="login"]/button[@type="submit"]')))) - .then(() => driver.wait(until - .elementLocated(By.xpath('//form[@id="login"]/div[@class="error"]')))) - .then(() => findByXpath('//form/div[@class="error"]')) + .then(() => clickCss('form#login button')) + .then(() => findByCss('form#login .error')) + .then((element) => { + driver.wait(until.elementIsVisible(element)); + return element; + }) .then((element) => element.getText()) .then((text) => t.match(text, 'Incorrect username or password.', '"Incorrect username or password" error should be displayed'))