Merge pull request #6287 from BryceLTaylor/convert-Tap-to-Jest-login-failures

Convert login failure integration tests from tap to jest
This commit is contained in:
Bryce Taylor 2021-11-15 10:53:42 -05:00 committed by GitHub
commit 0fd07274d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 110 deletions

18
package-lock.json generated
View file

@ -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": {

View file

@ -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",

View file

@ -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());
});

View file

@ -199,6 +199,10 @@ class SeleniumHelper {
return false;
}
async waitUntilVisible (element, driver) {
await driver.wait(until.elementIsVisible(element));
}
}
module.exports = SeleniumHelper;

View file

@ -7,7 +7,9 @@ const {
findByXpath,
clickXpath,
clickButton,
buildDriver
buildDriver,
signIn,
waitUntilVisible
} = new SeleniumHelper();
let username = process.env.SMOKE_USERNAME;
@ -30,6 +32,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);
@ -71,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);
});
@ -101,8 +100,61 @@ describe('www-integration sign-in-and-out', () => {
});
afterAll(async () => {
await driver.quit();
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.');
});
});
});