2018-11-05 14:02:06 +01:00
|
|
|
const assert = require('assert')
|
|
|
|
const webdriver = require('selenium-webdriver')
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2018-11-05 14:02:06 +01:00
|
|
|
const { By, until } = webdriver
|
|
|
|
const {
|
2020-01-13 16:07:32 +01:00
|
|
|
tinyDelayMs,
|
|
|
|
regularDelayMs,
|
|
|
|
largeDelayMs,
|
2018-11-05 14:02:06 +01:00
|
|
|
} = require('./helpers')
|
2020-01-14 18:34:38 +01:00
|
|
|
const { buildWebDriver } = require('./webdriver')
|
2019-12-09 15:40:43 +01:00
|
|
|
const Ganache = require('./ganache')
|
2019-10-23 19:00:16 +02:00
|
|
|
const enLocaleMessages = require('../../app/_locales/en/messages.json')
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2019-12-09 15:40:43 +01:00
|
|
|
const ganacheServer = new Ganache()
|
|
|
|
|
2018-11-05 14:02:06 +01:00
|
|
|
describe('MetaMask', function () {
|
|
|
|
let driver
|
|
|
|
|
|
|
|
const testSeedPhrase = 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent'
|
|
|
|
|
|
|
|
this.timeout(0)
|
|
|
|
this.bail(true)
|
|
|
|
|
|
|
|
before(async function () {
|
2019-12-09 15:40:43 +01:00
|
|
|
await ganacheServer.start()
|
2020-01-14 18:34:38 +01:00
|
|
|
const result = await buildWebDriver({ responsive: true })
|
2019-09-07 09:13:58 +02:00
|
|
|
driver = result.driver
|
2019-03-05 16:45:01 +01:00
|
|
|
})
|
|
|
|
|
2018-11-05 14:02:06 +01:00
|
|
|
afterEach(async function () {
|
|
|
|
if (process.env.SELENIUM_BROWSER === 'chrome') {
|
2020-01-13 16:07:32 +01:00
|
|
|
const errors = await driver.checkBrowserForConsoleErrors(driver)
|
2018-11-05 14:02:06 +01:00
|
|
|
if (errors.length) {
|
2020-02-15 21:34:12 +01:00
|
|
|
const errorReports = errors.map((err) => err.message)
|
2018-11-05 14:02:06 +01:00
|
|
|
const errorMessage = `Errors found in browser console:\n${errorReports.join('\n')}`
|
|
|
|
console.error(new Error(errorMessage))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.currentTest.state === 'failed') {
|
2020-07-09 17:01:14 +02:00
|
|
|
await driver.verboseReportOnFailure(this.currentTest.title)
|
2018-11-05 14:02:06 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
2019-12-09 15:40:43 +01:00
|
|
|
await ganacheServer.quit()
|
2018-11-05 14:02:06 +01:00
|
|
|
await driver.quit()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Going through the first time flow', function () {
|
|
|
|
it('clicks the continue button on the welcome screen', async function () {
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.findElement(By.css('.welcome-page__header'))
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks the "Create New Wallet" option', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Create a Wallet')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks the "I agree" option on the metametrics opt-in screen', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.btn-primary'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('accepts a secure password', async function () {
|
2020-01-13 16:07:32 +01:00
|
|
|
const passwordBox = await driver.findElement(By.css('.first-time-flow__form #create-password'))
|
|
|
|
const passwordBoxConfirm = await driver.findElement(By.css('.first-time-flow__form #confirm-password'))
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
await passwordBox.sendKeys('correct horse battery staple')
|
|
|
|
await passwordBoxConfirm.sendKeys('correct horse battery staple')
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.first-time-flow__checkbox'))
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.first-time-flow__form button'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
let seedPhrase
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('reveals the seed phrase', async function () {
|
2019-07-31 22:17:11 +02:00
|
|
|
const byRevealButton = By.css('.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button')
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(byRevealButton)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
const revealedSeedPhrase = await driver.findElement(By.css('.reveal-seed-phrase__secret-words'))
|
|
|
|
seedPhrase = await revealedSeedPhrase.getText()
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal(seedPhrase.split(' ').length, 12)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.next.message}')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
async function clickWordAndWait (word) {
|
2020-01-29 20:42:46 +01:00
|
|
|
await driver.clickElement(By.css(`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(tinyDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('can retype the seed phrase', async function () {
|
2019-07-31 22:17:11 +02:00
|
|
|
const words = seedPhrase.split(' ')
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2019-10-23 19:00:16 +02:00
|
|
|
for (const word of words) {
|
|
|
|
await clickWordAndWait(word)
|
|
|
|
}
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Confirm')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks through the success screen', async function () {
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.findElement(By.xpath(`//div[contains(text(), 'Congratulations')]`))
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Show account information', function () {
|
|
|
|
it('show account details dropdown menu', async function () {
|
2020-05-27 17:31:53 +02:00
|
|
|
await driver.clickElement(By.css('[data-testid="account-options-menu-button"]'))
|
|
|
|
const options = await driver.findElements(By.css('.account-options-menu .menu-item'))
|
2020-06-17 05:40:56 +02:00
|
|
|
assert.equal(options.length, 3) // HD Wallet type does not have to show the Remove Account option
|
2020-05-27 17:31:53 +02:00
|
|
|
// click outside of menu to dismiss
|
|
|
|
// account menu button chosen because the menu never covers it.
|
|
|
|
await driver.clickPoint(By.css('.account-menu__icon'), 0, 0)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Import seed phrase', function () {
|
|
|
|
it('logs out of the vault', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.account-menu__icon'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-01-21 23:09:53 +01:00
|
|
|
const lockButton = await driver.findClickableElement(By.css('.account-menu__lock-button'))
|
|
|
|
assert.equal(await lockButton.getText(), 'Lock')
|
|
|
|
await lockButton.click()
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('imports seed phrase', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
const restoreSeedLink = await driver.findClickableElement(By.css('.unlock-page__link--import'))
|
2018-11-05 14:02:06 +01:00
|
|
|
assert.equal(await restoreSeedLink.getText(), 'Import using account seed phrase')
|
|
|
|
await restoreSeedLink.click()
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
const seedTextArea = await driver.findElement(By.css('textarea'))
|
2018-11-05 14:02:06 +01:00
|
|
|
await seedTextArea.sendKeys(testSeedPhrase)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
|
|
|
const passwordInputs = await driver.findElements(By.css('input'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
|
|
|
await passwordInputs[0].sendKeys('correct horse battery staple')
|
|
|
|
await passwordInputs[1].sendKeys('correct horse battery staple')
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.restore.message}')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('switches to localhost', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.network-name'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//span[contains(text(), 'Localhost')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs * 2)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('balance renders', async function () {
|
2020-07-09 22:33:37 +02:00
|
|
|
const balance = await driver.findElement(By.css('[data-testid="eth-overview__primary-currency"]'))
|
2020-08-14 13:48:42 +02:00
|
|
|
await driver.wait(until.elementTextMatches(balance, /100\s*ETH/u))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Send ETH from inside MetaMask', function () {
|
2018-11-05 14:02:06 +01:00
|
|
|
it('starts to send a transaction', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Send')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
const inputAddress = await driver.findElement(By.css('input[placeholder="Search, public address (0x), or ENS"]'))
|
2018-11-05 14:02:06 +01:00
|
|
|
await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970')
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
const inputAmount = await driver.findElement(By.css('.unit-input__input'))
|
2018-11-05 14:02:06 +01:00
|
|
|
await inputAmount.sendKeys('1')
|
|
|
|
|
|
|
|
const inputValue = await inputAmount.getAttribute('value')
|
|
|
|
assert.equal(inputValue, '1')
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 17:50:06 +01:00
|
|
|
})
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2018-11-05 17:50:06 +01:00
|
|
|
it('opens and closes the gas modal', async function () {
|
2018-11-05 14:02:06 +01:00
|
|
|
// Set the gas limit
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.advanced-gas-options-btn'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
|
|
|
const gasModal = await driver.findElement(By.css('span .modal'))
|
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.page-container__header-close-text'))
|
2018-11-05 17:50:06 +01:00
|
|
|
await driver.wait(until.stalenessOf(gasModal), 10000)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 17:50:06 +01:00
|
|
|
})
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2018-11-05 17:50:06 +01:00
|
|
|
it('clicks through to the confirm screen', async function () {
|
2018-11-05 14:02:06 +01:00
|
|
|
// Continue to next screen
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('confirms the transaction', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Confirm')]`))
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('finds the transaction in the transactions list', async function () {
|
2020-06-11 22:14:07 +02:00
|
|
|
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'))
|
2019-10-31 17:27:22 +01:00
|
|
|
await driver.wait(async () => {
|
2020-01-13 16:07:32 +01:00
|
|
|
const confirmedTxes = await driver.findElements(By.css('.transaction-list__completed-transactions .transaction-list-item'))
|
2019-10-31 17:27:22 +01:00
|
|
|
return confirmedTxes.length === 1
|
|
|
|
}, 10000)
|
2018-11-05 14:02:06 +01:00
|
|
|
|
2020-05-26 22:49:11 +02:00
|
|
|
const txValues = await driver.findElement(By.css('.transaction-list-item__primary-currency'))
|
2020-08-14 13:48:42 +02:00
|
|
|
await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/u), 10000)
|
2018-11-05 14:02:06 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|