@ -10,7 +10,6 @@ const {
closeAllWindowHandlesExcept ,
closeAllWindowHandlesExcept ,
findElement ,
findElement ,
findElements ,
findElements ,
loadExtension ,
openNewPage ,
openNewPage ,
switchToWindowWithTitle ,
switchToWindowWithTitle ,
verboseReportOnFailure ,
verboseReportOnFailure ,
@ -18,9 +17,9 @@ const {
setupFetchMocking ,
setupFetchMocking ,
prepareExtensionForTesting ,
prepareExtensionForTesting ,
} = require ( './helpers' )
} = require ( './helpers' )
const enLocaleMessages = require ( '../../app/_locales/en/messages.json' )
describe ( 'MetaMask' , function ( ) {
describe ( 'MetaMask' , function ( ) {
let extensionId
let driver
let driver
let tokenAddress
let tokenAddress
@ -35,7 +34,6 @@ describe('MetaMask', function () {
before ( async function ( ) {
before ( async function ( ) {
const result = await prepareExtensionForTesting ( )
const result = await prepareExtensionForTesting ( )
driver = result . driver
driver = result . driver
extensionId = result . extensionId
await setupFetchMocking ( driver )
await setupFetchMocking ( driver )
} )
} )
@ -60,7 +58,7 @@ describe('MetaMask', function () {
describe ( 'Going through the first time flow' , ( ) => {
describe ( 'Going through the first time flow' , ( ) => {
it ( 'clicks the continue button on the welcome screen' , async ( ) => {
it ( 'clicks the continue button on the welcome screen' , async ( ) => {
await findElement ( driver , By . css ( '.welcome-page__header' ) )
await findElement ( driver , By . css ( '.welcome-page__header' ) )
const welcomeScreenBtn = await findElement ( driver , By . css ( '.first-time-flow__button' ) )
const welcomeScreenBtn = await findElement ( driver , By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . getStarted . message } ')] ` ) )
welcomeScreenBtn . click ( )
welcomeScreenBtn . click ( )
await delay ( largeDelayMs )
await delay ( largeDelayMs )
} )
} )
@ -105,7 +103,7 @@ describe('MetaMask', function () {
assert . equal ( seedPhrase . split ( ' ' ) . length , 12 )
assert . equal ( seedPhrase . split ( ' ' ) . length , 12 )
await delay ( regularDelayMs )
await delay ( regularDelayMs )
const nextScreen = ( await findElements ( driver , By . css ( 'button.first-time-flow__button' ) ) ) [ 1 ]
const nextScreen = await findElement ( driver , By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . next . message } ')] ` ) )
await nextScreen . click ( )
await nextScreen . click ( )
await delay ( regularDelayMs )
await delay ( regularDelayMs )
} )
} )
@ -118,37 +116,12 @@ describe('MetaMask', function () {
await delay ( tinyDelayMs )
await delay ( tinyDelayMs )
}
}
async function retypeSeedPhrase ( words , wasReloaded , count = 0 ) {
try {
if ( wasReloaded ) {
const byRevealButton = By . css ( '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button' )
await driver . wait ( until . elementLocated ( byRevealButton , 10000 ) )
const revealSeedPhraseButton = await findElement ( driver , byRevealButton , 10000 )
await revealSeedPhraseButton . click ( )
await delay ( regularDelayMs )
const nextScreen = await findElement ( driver , By . css ( 'button.first-time-flow__button' ) )
await nextScreen . click ( )
await delay ( regularDelayMs )
}
for ( let i = 0 ; i < 12 ; i ++ ) {
await clickWordAndWait ( words [ i ] )
}
} catch ( e ) {
if ( count > 2 ) {
throw e
} else {
await loadExtension ( driver , extensionId )
await retypeSeedPhrase ( words , true , count + 1 )
}
}
}
it ( 'can retype the seed phrase' , async ( ) => {
it ( 'can retype the seed phrase' , async ( ) => {
const words = seedPhrase . split ( ' ' )
const words = seedPhrase . split ( ' ' )
await retypeSeedPhrase ( words )
for ( const word of words ) {
await clickWordAndWait ( word )
}
const confirm = await findElement ( driver , By . xpath ( ` //button[contains(text(), 'Confirm')] ` ) )
const confirm = await findElement ( driver , By . xpath ( ` //button[contains(text(), 'Confirm')] ` ) )
await confirm . click ( )
await confirm . click ( )
@ -157,7 +130,7 @@ describe('MetaMask', function () {
it ( 'clicks through the success screen' , async ( ) => {
it ( 'clicks through the success screen' , async ( ) => {
await findElement ( driver , By . xpath ( ` //div[contains(text(), 'Congratulations')] ` ) )
await findElement ( driver , By . xpath ( ` //div[contains(text(), 'Congratulations')] ` ) )
const doneButton = await findElement ( driver , By . css ( 'button.first-time-flow__button' ) )
const doneButton = await findElement ( driver , By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . endOfFlowMessage10 . message } ')] ` ) )
await doneButton . click ( )
await doneButton . click ( )
await delay ( regularDelayMs )
await delay ( regularDelayMs )
} )
} )
@ -249,7 +222,7 @@ describe('MetaMask', function () {
await passwordInputs [ 0 ] . sendKeys ( 'correct horse battery staple' )
await passwordInputs [ 0 ] . sendKeys ( 'correct horse battery staple' )
await passwordInputs [ 1 ] . sendKeys ( 'correct horse battery staple' )
await passwordInputs [ 1 ] . sendKeys ( 'correct horse battery staple' )
await driver . findElement ( By . css ( '.first-time-flow__button' ) ) . click ( )
await driver . findElement ( By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . restore . message } ')] ` ) ) . click ( )
await delay ( regularDelayMs )
await delay ( regularDelayMs )
} )
} )
@ -475,13 +448,13 @@ describe('MetaMask', function () {
await approveButton . click ( )
await approveButton . click ( )
await driver . switchTo ( ) . window ( dapp )
await driver . switchTo ( ) . window ( dapp )
await delay ( regularDelayMs )
await delay ( 2000 )
} )
} )
it ( 'initiates a send from the dapp' , async ( ) => {
it ( 'initiates a send from the dapp' , async ( ) => {
const send3eth = await findElement ( driver , By . xpath ( ` //button[contains(text(), 'Send')] ` ) , 10000 )
const send3eth = await findElement ( driver , By . xpath ( ` //button[contains(text(), 'Send')] ` ) , 10000 )
await send3eth . click ( )
await send3eth . click ( )
await delay ( 5 000)
await delay ( 2 000)
windowHandles = await driver . getAllWindowHandles ( )
windowHandles = await driver . getAllWindowHandles ( )
await switchToWindowWithTitle ( driver , 'MetaMask Notification' , windowHandles )
await switchToWindowWithTitle ( driver , 'MetaMask Notification' , windowHandles )