From bbfbf8d7317df5dc639a47a0f7379b6c6c3312b6 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 8 Nov 2021 16:33:54 -0500 Subject: [PATCH 1/6] Move afterAll from sign-in-and-out tests earlier for understandability --- test/integration/sign-in-and-out.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/sign-in-and-out.test.js b/test/integration/sign-in-and-out.test.js index c2c93027f..5e5fc6750 100644 --- a/test/integration/sign-in-and-out.test.js +++ b/test/integration/sign-in-and-out.test.js @@ -30,6 +30,10 @@ describe('www-integration sign-in-and-out', () => { driver = await buildDriver('www-integration sign-in-out'); }); + afterAll(async () => { + await driver.quit(); + }); + describe('sign in', () => { afterEach(async () => { await driver.get(wwwURL); @@ -101,8 +105,6 @@ describe('www-integration sign-in-and-out', () => { }); - afterAll(async () => { - await driver.quit(); }); }); From 6992ca707fd45ba593e138da216c9a5d0df69e82 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 8 Nov 2021 16:37:15 -0500 Subject: [PATCH 2/6] Create waitUntilVisible SeleniumHelper function for Jest tests. --- test/integration/selenium-helpers.js | 4 ++++ test/integration/sign-in-and-out.test.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/integration/selenium-helpers.js b/test/integration/selenium-helpers.js index 4c38cd454..fbefe1799 100644 --- a/test/integration/selenium-helpers.js +++ b/test/integration/selenium-helpers.js @@ -199,6 +199,10 @@ class SeleniumHelper { return false; } + async waitUntilVisible (element, driver) { + await driver.wait(until.elementIsVisible(element)); + } + } module.exports = SeleniumHelper; diff --git a/test/integration/sign-in-and-out.test.js b/test/integration/sign-in-and-out.test.js index 5e5fc6750..1ecd5fbc4 100644 --- a/test/integration/sign-in-and-out.test.js +++ b/test/integration/sign-in-and-out.test.js @@ -7,7 +7,8 @@ const { findByXpath, clickXpath, clickButton, - buildDriver + buildDriver, + waitUntilVisible } = new SeleniumHelper(); let username = process.env.SMOKE_USERNAME; From c532e4498b740f2dc40e6a42f5dcec94058a2b87 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 8 Nov 2021 16:38:25 -0500 Subject: [PATCH 3/6] Move test-login-failures integration tests to in sign-in-and-out jest tests --- .../smoke-testing/test-login-failures.js | 89 ------------------- test/integration/sign-in-and-out.test.js | 57 ++++++++++++ 2 files changed, 57 insertions(+), 89 deletions(-) delete mode 100644 test/integration-legacy/smoke-testing/test-login-failures.js diff --git a/test/integration-legacy/smoke-testing/test-login-failures.js b/test/integration-legacy/smoke-testing/test-login-failures.js deleted file mode 100644 index a629bb5fd..000000000 --- a/test/integration-legacy/smoke-testing/test-login-failures.js +++ /dev/null @@ -1,89 +0,0 @@ -const SeleniumHelper = require('../selenium-helpers.js'); -const helper = new SeleniumHelper(); - -var tap = require('tap'); -const test = tap.test; - -const webdriver = require('selenium-webdriver'); -const driver = helper.buildDriver('www-smoke test-login-failures'); - -const { - findByCss, - clickCss -} = helper; - -var until = webdriver.until; - -var username = process.env.SMOKE_USERNAME; -var password = process.env.SMOKE_PASSWORD; - -var rootUrl = process.env.ROOT_URL || 'https://scratch.ly'; -var url = rootUrl + '/users/' + username; - -tap.plan(3); - -tap.tearDown(function () { - driver.quit(); -}); - -tap.beforeEach(function () { - return driver.get(url); -}); - -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); - clickCss('.dropdown-toggle') - .then(() => findByCss('form#login input#login_dropdown_username')) - .then((element) => element.sendKeys(nonsenseusername)) - .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', - '"This field is required" error should be displayed')) - .then(() => t.end()); -}); - -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); - clickCss('.dropdown-toggle') - .then(() => findByCss('form#login input#login_dropdown_username')) - .then((element) => element.sendKeys(nonsenseusername)) - .then(() => findByCss('form#login input.wide.password')) - .then((element) => element.sendKeys(password)) - .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')) - .then(() => t.end()); -}); - -test('Trying to sign in with the wrong password using scratchr2 navbar', t => { - clickCss('.dropdown-toggle') - .then(() => findByCss('form#login input#login_dropdown_username')) - .then((element) => element.sendKeys(username)) - .then(() => findByCss('form#login input.wide.password')) - .then((element) => element.sendKeys('nonsensepassword')) - .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')) - .then(() => t.end()); -}); diff --git a/test/integration/sign-in-and-out.test.js b/test/integration/sign-in-and-out.test.js index 1ecd5fbc4..632df5808 100644 --- a/test/integration/sign-in-and-out.test.js +++ b/test/integration/sign-in-and-out.test.js @@ -106,6 +106,63 @@ describe('www-integration sign-in-and-out', () => { }); + describe('login failures', async () => { + + + test('sign in with no password in Scratchr2', async () => { + let nonsenseUsername = Math.random().toString(36) + .replace(/[^a-z]+/g, '') + .substr(0, 5); + await driver.get(scratchr2url); + await clickXpath('//li[@class="sign-in dropdown"]/span'); + let name = await findByXpath('//input[@id="login_dropdown_username"]'); + await name.sendKeys(nonsenseUsername); + await clickButton('Sign in'); + + // find error + let error = await findByXpath('//form[@id="login"]//div[@class="error"]'); + let errorText = await error.getText(); + await expect(errorText).toEqual('This field is required.'); + }); + + test('sign in with wrong username', async () => { + let nonsenseUsername = Math.random().toString(36) + .replace(/[^a-z]+/g, '') + .substr(0, 5); + await driver.get(scratchr2url); + await clickXpath('//li[@class="sign-in dropdown"]/span'); + let name = await findByXpath('//input[@id="login_dropdown_username"]'); + await name.sendKeys(nonsenseUsername); + let word = await findByXpath('//input[@name="password"]'); + await word.sendKeys(password); + await clickButton('Sign in'); + + // find error + let error = await findByXpath('//form[@id="login"]//div[@class="error"]'); + await waitUntilVisible(error, driver); + let errorText = await error.getText(); + await expect(errorText).toEqual('Incorrect username or password.'); + }); + + test('sign in with wrong password', async () => { + let nonsensePassword = Math.random().toString(36) + .replace(/[^a-z]+/g, '') + .substr(0, 5); + await driver.get(scratchr2url); + await clickXpath('//li[@class="sign-in dropdown"]/span'); + let name = await findByXpath('//input[@id="login_dropdown_username"]'); + await name.sendKeys(username); + let word = await findByXpath('//input[@name="password"]'); + await word.sendKeys(nonsensePassword); + await clickButton('Sign in'); + + // find error + let error = await findByXpath('//form[@id="login"]//div[@class="error"]'); + await waitUntilVisible(error, driver); + let errorText = await error.getText(); + await expect(errorText).toEqual('Incorrect username or password.'); + }); + }); }); From 56e8670ec74673a9342420a2b0570da7211b3be8 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 8 Nov 2021 16:47:39 -0500 Subject: [PATCH 4/6] Use SeleniumHelpers signIn function in sign-out integration tests --- test/integration/sign-in-and-out.test.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/integration/sign-in-and-out.test.js b/test/integration/sign-in-and-out.test.js index 632df5808..64db2c24f 100644 --- a/test/integration/sign-in-and-out.test.js +++ b/test/integration/sign-in-and-out.test.js @@ -8,6 +8,7 @@ const { clickXpath, clickButton, buildDriver, + signIn, waitUntilVisible } = new SeleniumHelper(); @@ -76,14 +77,7 @@ describe('www-integration sign-in-and-out', () => { describe('sign out', () => { beforeEach(async () => { await driver.get(wwwURL); - await clickXpath('//li[@class="link right login-item"]'); - let name = await findByXpath('//input[@id="frc-username-1088"]'); - await name.sendKeys(username); - let word = await findByXpath('//input[@id="frc-password-1088"]'); - await word.sendKeys(password); - await driver.sleep(500); - await clickXpath('//button[contains(@class, "button") and ' + - 'contains(@class, "submit-button") and contains(@class, "white")]'); + await signIn(username, password, driver); await driver.sleep(500); }); From bcdcb58c9618e82013be99fb8576a92814eb690c Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 8 Nov 2021 16:48:01 -0500 Subject: [PATCH 5/6] Update Chromedriver to version 95.0.0 --- package-lock.json | 18 +++++++++--------- package.json | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1a4658fbe..1f2280f74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4649,9 +4649,9 @@ } }, "chromedriver": { - "version": "94.0.0", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-94.0.0.tgz", - "integrity": "sha512-x4hK7R7iOyAhdLHJEcOyGBW/oa2kno6AqpHVLd+n3G7c2Vk9XcAXMz84XhNItqykJvTc6E3z/JRIT1eHYH//Eg==", + "version": "95.0.0", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-95.0.0.tgz", + "integrity": "sha512-HwSg7S0ZZYsHTjULwxFHrrUqEpz1+ljDudJM3eOquvqD5QKnR5pSe/GlBTY9UU2tVFRYz8bEHYC4Y8qxciQiLQ==", "dev": true, "requires": { "@testim/chrome-version": "^1.0.7", @@ -6285,9 +6285,9 @@ "dev": true }, "ignore": { - "version": "5.1.8", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", - "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "version": "5.1.9", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.9.tgz", + "integrity": "sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==", "dev": true }, "is-extglob": { @@ -8514,9 +8514,9 @@ } }, "follow-redirects": { - "version": "1.14.4", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz", - "integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==", + "version": "1.14.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz", + "integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==", "dev": true }, "font-atlas": { diff --git a/package.json b/package.json index 777c171ae..5fc1aa7cb 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "babel-preset-es2015": "6.22.0", "babel-preset-react": "6.22.0", "bowser": "1.9.4", - "chromedriver": "94.0.0", + "chromedriver": "95.0.0", "classnames": "2.2.5", "cookie": "0.4.1", "copy-webpack-plugin": "4.6.0", From e4b4cbf5f696b12c48e648715f5df685bffb861d Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 8 Nov 2021 16:58:02 -0500 Subject: [PATCH 6/6] cleanup whitespace in sign-in-and-out integration tests --- test/integration/sign-in-and-out.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/integration/sign-in-and-out.test.js b/test/integration/sign-in-and-out.test.js index 64db2c24f..34534d052 100644 --- a/test/integration/sign-in-and-out.test.js +++ b/test/integration/sign-in-and-out.test.js @@ -101,8 +101,6 @@ describe('www-integration sign-in-and-out', () => { }); describe('login failures', async () => { - - test('sign in with no password in Scratchr2', async () => { let nonsenseUsername = Math.random().toString(36) .replace(/[^a-z]+/g, '')