2018-03-29 22:49:54 +02:00
const fs = require ( 'fs' )
const mkdirp = require ( 'mkdirp' )
2017-09-12 23:14:24 +02:00
const path = require ( 'path' )
const assert = require ( 'assert' )
2018-03-29 22:49:54 +02:00
const pify = require ( 'pify' )
2017-09-12 23:14:24 +02:00
const webdriver = require ( 'selenium-webdriver' )
const By = webdriver . By
const { delay , buildWebDriver } = require ( './func' )
describe ( 'Metamask popup page' , function ( ) {
let driver
this . seedPhase
this . accountAddress
this . timeout ( 0 )
before ( async function ( ) {
const extPath = path . resolve ( 'dist/chrome' )
driver = buildWebDriver ( extPath )
await driver . get ( 'chrome://extensions-frame' )
2018-03-29 20:59:13 +02:00
const elems = await driver . findElements ( By . css ( '.extension-list-item-wrapper' ) )
2018-03-10 08:57:44 +01:00
const extensionId = await elems [ 1 ] . getAttribute ( 'id' )
2017-09-12 23:14:24 +02:00
await driver . get ( ` chrome-extension:// ${ extensionId } /popup.html ` )
await delay ( 500 )
} )
2018-03-29 22:49:54 +02:00
afterEach ( async function ( ) {
if ( this . currentTest . state === 'failed' ) {
await verboseReportOnFailure ( this . currentTest )
}
} )
2017-09-12 23:14:24 +02:00
after ( async function ( ) {
await driver . quit ( )
} )
describe ( '#onboarding' , ( ) => {
it ( 'should open Metamask.io' , async function ( ) {
const tabs = await driver . getAllWindowHandles ( )
await driver . switchTo ( ) . window ( tabs [ 0 ] )
await delay ( 300 )
2018-03-30 22:52:42 +02:00
await setProviderType ( 'localhost' )
await delay ( 300 )
2017-09-12 23:14:24 +02:00
} )
it ( 'should match title' , async ( ) => {
const title = await driver . getTitle ( )
2018-03-28 22:37:02 +02:00
assert . equal ( title , 'MetaMask' , 'title matches MetaMask' )
2017-09-12 23:14:24 +02:00
} )
it ( 'should show privacy notice' , async ( ) => {
2018-03-29 20:59:13 +02:00
const privacy = await driver . findElement ( By . css ( '.terms-header' ) ) . getText ( )
2017-09-12 23:14:24 +02:00
assert . equal ( privacy , 'PRIVACY NOTICE' , 'shows privacy notice' )
2018-03-29 22:49:54 +02:00
driver . findElement ( By . css ( 'button' ) ) . click ( )
2018-03-29 21:06:23 +02:00
await delay ( 300 )
2017-09-12 23:14:24 +02:00
} )
it ( 'should show terms of use' , async ( ) => {
await delay ( 300 )
2018-03-29 20:59:13 +02:00
const terms = await driver . findElement ( By . css ( '.terms-header' ) ) . getText ( )
2017-09-12 23:14:24 +02:00
assert . equal ( terms , 'TERMS OF USE' , 'shows terms of use' )
2018-03-29 21:06:23 +02:00
await delay ( 300 )
2017-09-12 23:14:24 +02:00
} )
it ( 'should be unable to continue without scolling throught the terms of use' , async ( ) => {
2018-03-29 22:49:54 +02:00
const button = await driver . findElement ( By . css ( 'button' ) ) . isEnabled ( )
2017-09-12 23:14:24 +02:00
assert . equal ( button , false , 'disabled continue button' )
const element = driver . findElement ( By . linkText (
'Attributions'
) )
await driver . executeScript ( 'arguments[0].scrollIntoView(true)' , element )
2018-03-29 21:06:23 +02:00
await delay ( 300 )
2017-09-12 23:14:24 +02:00
} )
it ( 'should be able to continue when scrolled to the bottom of terms of use' , async ( ) => {
const button = await driver . findElement ( By . css ( 'button' ) )
const buttonEnabled = await button . isEnabled ( )
await delay ( 500 )
assert . equal ( buttonEnabled , true , 'enabled continue button' )
await button . click ( )
2018-03-29 21:06:23 +02:00
await delay ( 300 )
2017-09-12 23:14:24 +02:00
} )
it ( 'should accept password with length of eight' , async ( ) => {
const passwordBox = await driver . findElement ( By . id ( 'password-box' ) )
2018-03-10 08:57:44 +01:00
const passwordBoxConfirm = await driver . findElement ( By . id ( 'password-box-confirm' ) )
2017-09-12 23:14:24 +02:00
const button = driver . findElement ( By . css ( 'button' ) )
2018-03-10 08:57:44 +01:00
passwordBox . sendKeys ( '123456789' )
passwordBoxConfirm . sendKeys ( '123456789' )
await delay ( 500 )
2017-09-12 23:14:24 +02:00
await button . click ( )
} )
it ( 'should show value was created and seed phrase' , async ( ) => {
await delay ( 700 )
2018-03-29 20:59:13 +02:00
this . seedPhase = await driver . findElement ( By . css ( '.twelve-word-phrase' ) ) . getText ( )
2017-09-12 23:14:24 +02:00
const continueAfterSeedPhrase = await driver . findElement ( By . css ( 'button' ) )
await continueAfterSeedPhrase . click ( )
2018-03-29 21:06:23 +02:00
await delay ( 300 )
2017-09-12 23:14:24 +02:00
} )
it ( 'should show lock account' , async ( ) => {
2018-03-29 20:59:13 +02:00
await driver . findElement ( By . css ( '.sandwich-expando' ) ) . click ( )
2017-09-12 23:14:24 +02:00
await delay ( 500 )
2018-03-29 22:54:01 +02:00
await driver . findElement ( By . css ( '#app-content > div > div:nth-child(3) > span > div > li:nth-child(3)' ) ) . click ( )
2017-09-12 23:14:24 +02:00
} )
it ( 'should accept account password after lock' , async ( ) => {
await delay ( 500 )
2018-03-10 08:57:44 +01:00
await driver . findElement ( By . id ( 'password-box' ) ) . sendKeys ( '123456789' )
2017-09-12 23:14:24 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
await delay ( 500 )
} )
2018-03-29 20:59:13 +02:00
it ( 'should show QR code option' , async ( ) => {
2017-09-12 23:14:24 +02:00
await delay ( 300 )
2018-03-29 20:59:13 +02:00
await driver . findElement ( By . css ( '.fa-ellipsis-h' ) ) . click ( )
await driver . findElement ( By . css ( '#app-content > div > div.app-primary.from-right > div > div > div:nth-child(1) > flex-column > div.name-label > div > span > i > div > div > li:nth-child(3)' ) ) . click ( )
2017-09-12 23:14:24 +02:00
await delay ( 300 )
} )
it ( 'should show the account address' , async ( ) => {
2018-03-29 20:59:13 +02:00
this . accountAddress = await driver . findElement ( By . css ( '.ellip-address' ) ) . getText ( )
await driver . findElement ( By . css ( '.fa-arrow-left' ) ) . click ( )
2017-09-12 23:14:24 +02:00
await delay ( 500 )
} )
} )
2018-03-29 22:49:54 +02:00
2018-03-30 22:52:42 +02:00
async function setProviderType ( type ) {
await driver . executeScript ( 'window.metamask.setProviderType(arguments[0])' , type )
}
2018-03-29 22:49:54 +02:00
async function verboseReportOnFailure ( test ) {
const artifactDir = ` ./test-artifacts/ ${ test . title } `
const filepathBase = ` ${ artifactDir } /test-failure `
await pify ( mkdirp ) ( artifactDir )
// capture screenshot
const screenshot = await driver . takeScreenshot ( )
await pify ( fs . writeFile ) ( ` ${ filepathBase } -screenshot.png ` , screenshot , { encoding : 'base64' } )
// capture dom source
const htmlSource = await driver . getPageSource ( )
await pify ( fs . writeFile ) ( ` ${ filepathBase } -dom.html ` , htmlSource )
}
2017-09-12 23:14:24 +02:00
} )