change pass: add e2e tests

This commit is contained in:
dennistikhomirov 2018-08-22 06:27:50 -07:00
parent 85f3702291
commit fcb185bee4
2 changed files with 225 additions and 31 deletions

View File

@ -5,7 +5,8 @@ const os = require('os')
const path = require('path') const path = require('path')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const Command = require('selenium-webdriver/lib/command').Command const Command = require('selenium-webdriver/lib/command').Command
const By = webdriver.By
const { By, Key, until } = webdriver
module.exports = { module.exports = {
delay, delay,
@ -14,6 +15,7 @@ module.exports = {
installWebExt, installWebExt,
getExtensionIdChrome, getExtensionIdChrome,
getExtensionIdFirefox, getExtensionIdFirefox,
clearField
} }
function delay(time) { function delay(time) {
@ -61,3 +63,11 @@ async function installWebExt (driver, extension) {
return await driver.schedule(cmd, 'installWebExt(' + extension + ')') return await driver.schedule(cmd, 'installWebExt(' + extension + ')')
} }
async function clearField(field) {
await field.click();
await delay(200);
for ( let i = 0; i < 40; i++ ) {
await field.sendKeys(Key.BACK_SPACE);
}
}

View File

@ -5,15 +5,55 @@ const assert = require('assert')
const pify = require('pify') const pify = require('pify')
const webdriver = require('selenium-webdriver') const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver const { By, Key, until } = webdriver
const { delay, buildChromeWebDriver, buildFirefoxWebdriver, installWebExt, getExtensionIdChrome, getExtensionIdFirefox } = require('./func') const { clearField, delay, buildChromeWebDriver, buildFirefoxWebdriver, installWebExt, getExtensionIdChrome, getExtensionIdFirefox } = require('./func')
const accountsMenuSelector = '#app-content > div > div.full-width > div > div:nth-child(2) > span > div' const accountsMenuSelector = '#app-content > div > div.full-width > div > div:nth-child(2) > span > div'
const settingsTitleSelector = '#app-content > div > div.app-primary.from-right > div > div.section-title.flex-row.flex-center > h2' const settingsTitleSelector = '#app-content > div > div.app-primary.from-right > div > div.section-title.flex-row.flex-center > h2'
const deleteImportedAccountTitleSelector = '#app-content > div > div.app-primary.from-left > div > div.section-title.flex-row.flex-center > h2' const deleteImportedAccountTitleSelector = '#app-content > div > div.app-primary.from-left > div > div.section-title.flex-row.flex-center > h2'
const importedAccountRemoveIconSelector = '#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > div.remove' const importedAccountRemoveIconSelector = '#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > div.remove'
const importedLabelSelector = '#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > div.keyring-label' const importedLabelSelector = '#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(4) > div.keyring-label'
const buttonChangePassword = '#app-content > div > div.app-primary.from-right > div > div.flex-column.flex-justify-center.flex-grow.select-none > div > div:nth-child(10) > button:nth-child(5)'
let password = '123456789'
describe('Metamask popup page', function () { const sandwichMenuSelectors = {
Menu: '.sandwich-expando',
Settings: '#app-content > div > div:nth-child(3) > span > div > li:nth-child(2)',
LogOut: '#app-content > div > div:nth-child(3) > span > div > li:nth-child(3)'
}
const titlesOfScreensSelectors = {
ChangePassword: 'Change Password',
Settings: 'Settings'
}
const mainScreenSelectors = {
buttonBuy: '#app-content > div > div.app-primary.from-right > div > div > div.flex-row > button:nth-child(3)'
}
const screenChangePassword = {
ById: {
fieldOldPassword: 'old-password-box',
fieldNewPassword: 'new-password-box',
fieldConfirmNewPassword: 'password-box-confirm'
},
ByCss: {
buttonNo: '#app-content > div > div.app-primary.from-right > div > div.flex-row.flex-right > button.btn-violet',
buttonYes: '#app-content > div > div.app-primary.from-right > div > div.flex-row.flex-right > button:nth-child(2)',
},
ByClassName: {
label: 'confirm-label',
arrowLeft: 'fa fa-arrow-left fa-lg cursor-pointer',
error: 'error'
},
labelText: 'Are you sure you want to change the password for unlocking of your wallet?',
error: {
differ: 'New password should differ from the current one',
notLong: 'Password not long enough',
dontMatch: 'Passwords don\'t match',
incorrectPassword: 'Incorrect password'
}
}
describe('Metamask popup page', async function () {
let driver, accountAddress, tokenAddress, extensionId let driver, accountAddress, tokenAddress, extensionId
this.timeout(0) this.timeout(0)
@ -57,7 +97,7 @@ describe('Metamask popup page', function () {
await driver.quit() await driver.quit()
}) })
describe('Setup', function () { describe('Setup', async function () {
it('switches to Chrome extensions list', async function () { it('switches to Chrome extensions list', async function () {
await delay(300) await delay(300)
@ -72,7 +112,7 @@ describe('Metamask popup page', function () {
}) })
describe('Account Creation', () => { describe('Account Creation', async () => {
it('matches Nifty Wallet title', async () => { it('matches Nifty Wallet title', async () => {
const title = await driver.getTitle() const title = await driver.getTitle()
@ -104,8 +144,8 @@ describe('Metamask popup page', function () {
const passwordBoxConfirm = await driver.findElement(By.id('password-box-confirm')) const passwordBoxConfirm = await driver.findElement(By.id('password-box-confirm'))
const button = await driver.findElements(By.css('button')) const button = await driver.findElements(By.css('button'))
await passwordBox.sendKeys('123456789') await passwordBox.sendKeys(password)
await passwordBoxConfirm.sendKeys('123456789') await passwordBoxConfirm.sendKeys(password)
await button[0].click() await button[0].click()
await delay(500) await delay(500)
}) })
@ -142,7 +182,7 @@ describe('Metamask popup page', function () {
it('accepts account password after lock', async () => { it('accepts account password after lock', async () => {
await delay(500) await delay(500)
await driver.findElement(By.id('password-box')).sendKeys('123456789') await driver.findElement(By.id('password-box')).sendKeys(password)
await driver.findElement(By.id('password-box')).sendKeys(Key.ENTER) await driver.findElement(By.id('password-box')).sendKeys(Key.ENTER)
await delay(500) await delay(500)
}) })
@ -162,8 +202,150 @@ describe('Metamask popup page', function () {
}) })
}) })
describe('Change password', async () => {
const newPassword = {
correct: 'abcDEF123!@#',
short: '123',
incorrect: '1234567890'
}
let fieldNewPassword
let fieldConfirmNewPassword
let fieldOldPassword
let buttonYes
describe('check screen "Settings" -> "Change password" ', async () => {
it('checks if "Change password" button is present and enabled', async () => {
await driver.findElement(By.css(sandwichMenuSelectors.Menu)).click()
await delay(500)
await driver.findElement(By.css(sandwichMenuSelectors.Settings)).click()
await delay(500)
const buttons = await driver.findElements(By.css(buttonChangePassword))
assert.equal(buttons.length, 1, 'Button "Change password" is not present')
assert.equal(await buttons[0].isEnabled(), true, 'Button "Change password" is disabled')
})
it('screen contains correct title', async () => {
const button = await driver.findElement(By.css(buttonChangePassword))
await button.click()
const title = await driver.findElement(By.className('page-subtitle'))
assert.equal(await title.getText(), titlesOfScreensSelectors.ChangePassword, '"Change password" screen contains incorrect title')
})
it('screen contains correct label', async () => {
const labels = await driver.findElements(By.className(screenChangePassword.ByClassName.label))
assert.equal(labels.length, 1, 'screen "Change password" doesn\'t contain label')
assert.equal(await labels[0].getText(), screenChangePassword.labelText, 'label contains incorrect title')
})
it('clicking the button "No" bring back to "Setting" screen ', async () => {
const button = await driver.findElement(By.css(screenChangePassword.ByCss.buttonNo))
await button.click()
const title = await driver.findElement(By.css(settingsTitleSelector))
assert.equal(await title.getText(), titlesOfScreensSelectors.Settings, 'button "No" doesnt open settings screen')
const buttonChangePass = await driver.findElement(By.css(buttonChangePassword))
await buttonChangePass.click()
})
})
describe('Validation of errors ', async () => {
before(async () => {
fieldOldPassword = await driver.findElement(By.id(screenChangePassword.ById.fieldOldPassword))
await fieldOldPassword.sendKeys(password)
fieldNewPassword = await driver.findElement(By.id(screenChangePassword.ById.fieldNewPassword))
fieldConfirmNewPassword = await driver.findElement(By.id(screenChangePassword.ById.fieldConfirmNewPassword))
buttonYes = await driver.findElement(By.css(screenChangePassword.ByCss.buttonYes))
})
it('error if new password shorter than 8 digits', async () => {
await fieldNewPassword.sendKeys(newPassword.short)
await fieldConfirmNewPassword.sendKeys(newPassword.short)
await buttonYes.click()
const errors = await driver.findElements(By.className(screenChangePassword.ByClassName.error))
assert.equal(errors.length > 0, true, 'error isn\'t displayed')
assert.equal(await errors[0].getText(), screenChangePassword.error.notLong, 'Error\'s text incorrect')
})
it('error if new password doesn\'t match confirmation', async () => {
await clearField(fieldNewPassword)
await clearField(fieldConfirmNewPassword)
await fieldNewPassword.sendKeys(newPassword.correct)
await fieldConfirmNewPassword.sendKeys(newPassword.incorrect)
await buttonYes.click()
const errors = await driver.findElements(By.className(screenChangePassword.ByClassName.error))
assert.equal(errors.length > 0, true, 'error isn\'t displayed')
assert.equal(await errors[0].getText(), screenChangePassword.error.dontMatch, 'Error\'s text incorrect')
})
it('error if new password match old password', async () => {
await clearField(fieldNewPassword)
await clearField(fieldConfirmNewPassword)
await fieldNewPassword.sendKeys(password)
await fieldConfirmNewPassword.sendKeys(password)
await buttonYes.click()
const errors = await driver.findElements(By.className(screenChangePassword.ByClassName.error))
assert.equal(errors.length > 0, true, 'error isn\'t displayed')
assert.equal(await errors[0].getText(), screenChangePassword.error.differ, 'Error\'s text incorrect')
})
it.skip('error if old password incorrect ', async () => {
await clearField(fieldOldPassword)
await fieldOldPassword.sendKeys(newPassword.incorrect)
await buttonYes.click()
const errors = await driver.findElements(By.className(screenChangePassword.ByClassName.error))
assert.equal(errors.length > 0, true, 'error isn\'t displayed')
assert.equal(await errors[0].getText(), screenChangePassword.error.incorrectPassword, 'Error\'s text incorrect')
})
it('no errors if old, new, confirm new passwords are correct; user can change password', async () => {
await clearField(fieldNewPassword)
await clearField(fieldOldPassword)
await clearField(fieldConfirmNewPassword)
await fieldOldPassword.sendKeys(password)
await fieldNewPassword.sendKeys(newPassword.correct)
await fieldConfirmNewPassword.sendKeys(newPassword.correct)
await buttonYes.click()
await driver.wait(until.elementLocated(By.css(buttonChangePassword)))
const buttons = await driver.findElements(By.css(buttonChangePassword))
assert.equal(buttons.length, 1, 'Button "Change password" is not present')
assert.equal(await buttons[0].isEnabled(), true, 'Button "Change password" is disabled')
})
})
describe('Check if new password is accepted', async () => {
it('user can log out', async () => {
await driver.findElement(By.css(sandwichMenuSelectors.Menu)).click()
await delay(500)
await driver.wait(until.elementLocated(By.css(sandwichMenuSelectors.LogOut)))
const itemLogOut = await driver.findElement(By.css(sandwichMenuSelectors.LogOut))
await driver.wait(until.elementIsVisible(itemLogOut))
itemLogOut.click()
await driver.wait(until.elementLocated(By.id('password-box')))
const fields = await driver.findElements(By.id('password-box'))
assert.equal(fields.length, 1, 'password box isn\'t present after logout')
})
it('accepts new password after lock', async () => {
const field = await driver.findElement(By.id('password-box'))
await field.sendKeys(newPassword.correct)
await driver.findElement(By.className('cursor-pointer')).click()
await driver.wait(until.elementLocated(By.css(mainScreenSelectors.buttonBuy)))
const buttons = await driver.findElements(By.css(mainScreenSelectors.buttonBuy))
assert.equal(buttons.length, 1, 'main screen isn\'t displayed')
password = newPassword.correct
})
})
})
describe('Import Account', () => { describe('Import Account', () => {
it('opens import account menu', async function () { it('opens import account menu', async function () {
await driver.wait(until.elementLocated(By.css(accountsMenuSelector)))
await driver.findElement(By.css(accountsMenuSelector)).click() await driver.findElement(By.css(accountsMenuSelector)).click()
await delay(500) await delay(500)
await driver.findElement(By.css('#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(5) > span')).click() await driver.findElement(By.css('#app-content > div > div.full-width > div > div:nth-child(2) > span > div > div > span > div > li:nth-child(5) > span')).click()
@ -505,3 +687,5 @@ describe('Metamask popup page', function () {
} }
}) })