2018-03-30 02:02:40 +02:00
const path = require ( 'path' )
const fs = require ( 'fs' )
const pify = require ( 'pify' )
const mkdirp = require ( 'mkdirp' )
2018-03-30 09:09:39 +02:00
const rimraf = require ( 'rimraf' )
2018-03-30 02:02:40 +02:00
const webdriver = require ( 'selenium-webdriver' )
const endOfStream = require ( 'end-of-stream' )
const GIFEncoder = require ( 'gifencoder' )
const pngFileStream = require ( 'png-file-stream' )
const sizeOfPng = require ( 'image-size/lib/types/png' )
const By = webdriver . By
const { delay , buildWebDriver } = require ( './func' )
2018-03-30 09:48:37 +02:00
const localesIndex = require ( '../../app/_locales/index.json' )
2018-03-30 02:02:40 +02:00
2018-03-30 23:39:43 +02:00
let driver
captureAllScreens ( ) . catch ( ( err ) => {
try {
console . error ( err )
2018-03-30 23:48:41 +02:00
verboseReportOnFailure ( )
2018-03-30 23:39:43 +02:00
driver . quit ( )
2018-03-30 23:48:41 +02:00
} catch ( err ) {
console . error ( err )
2018-03-30 23:39:43 +02:00
}
2018-03-30 23:48:41 +02:00
process . exit ( 1 )
2018-03-30 23:39:43 +02:00
} )
2018-03-30 02:02:40 +02:00
async function captureAllScreens ( ) {
let screenshotCount = 0
2018-03-30 09:09:39 +02:00
// common names
let button
let tabs
let element
await cleanScreenShotDir ( )
2018-03-30 02:02:40 +02:00
// setup selenium and install extension
const extPath = path . resolve ( 'dist/chrome' )
2018-03-30 23:39:43 +02:00
driver = buildWebDriver ( extPath )
2018-03-30 02:02:40 +02:00
await driver . get ( 'chrome://extensions-frame' )
const elems = await driver . findElements ( By . css ( '.extension-list-item-wrapper' ) )
const extensionId = await elems [ 1 ] . getAttribute ( 'id' )
2018-03-30 09:09:39 +02:00
await driver . get ( ` chrome-extension:// ${ extensionId } /home.html ` )
2018-03-30 02:02:40 +02:00
await delay ( 500 )
2018-03-30 09:09:39 +02:00
tabs = await driver . getAllWindowHandles ( )
2018-03-30 02:02:40 +02:00
await driver . switchTo ( ) . window ( tabs [ 0 ] )
2018-03-31 03:14:26 +02:00
await delay ( 1000 )
2018-03-30 20:16:08 +02:00
await setProviderType ( 'localhost' )
2018-03-31 02:36:43 +02:00
await delay ( 300 )
2018-03-30 02:02:40 +02:00
// click try new ui
await driver . findElement ( By . css ( '#app-content > div > div.app-primary.from-right > div > div.flex-row.flex-center.flex-grow > p' ) ) . click ( )
await delay ( 300 )
2018-03-30 09:09:39 +02:00
// close metamask homepage and extra home.html
tabs = await driver . getAllWindowHandles ( )
2018-03-30 20:16:08 +02:00
// metamask homepage is opened on prod, not dev
if ( tabs . length > 2 ) {
await driver . switchTo ( ) . window ( tabs [ 2 ] )
driver . close ( )
}
2018-03-30 09:09:39 +02:00
await driver . switchTo ( ) . window ( tabs [ 1 ] )
driver . close ( )
await driver . switchTo ( ) . window ( tabs [ 0 ] )
2018-03-30 02:02:40 +02:00
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'welcome-new-ui' )
2018-03-30 09:09:39 +02:00
// setup account
await delay ( 1000 )
await driver . findElement ( By . css ( 'body' ) ) . click ( )
2018-03-30 02:02:40 +02:00
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'welcome' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'create password' )
2018-03-30 09:09:39 +02:00
const passwordBox = await driver . findElement ( By . css ( 'input[type=password]:nth-of-type(1)' ) )
const passwordBoxConfirm = await driver . findElement ( By . css ( 'input[type=password]:nth-of-type(2)' ) )
passwordBox . sendKeys ( '123456789' )
passwordBoxConfirm . sendKeys ( '123456789' )
await delay ( 500 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'choose-password-filled' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
await delay ( 500 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'unique account image' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
await delay ( 500 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'privacy note' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
2018-03-30 02:02:40 +02:00
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'terms' )
2018-03-30 02:02:40 +02:00
await delay ( 300 )
2018-03-30 09:09:39 +02:00
element = driver . findElement ( By . linkText ( 'Attributions' ) )
2018-03-30 02:02:40 +02:00
await driver . executeScript ( 'arguments[0].scrollIntoView(true)' , element )
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'terms-scrolled' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
2018-03-30 02:02:40 +02:00
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'secret backup phrase' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'secret backup phrase' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( '.backup-phrase__reveal-button' ) ) . click ( )
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'secret backup phrase - reveal' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
await driver . findElement ( By . css ( 'button' ) ) . click ( )
2018-03-30 02:02:40 +02:00
await delay ( 300 )
2018-03-30 09:48:37 +02:00
await captureLanguageScreenShots ( 'confirm secret backup phrase' )
2018-03-30 02:02:40 +02:00
2018-03-30 09:09:39 +02:00
// finish up
console . log ( 'building gif...' )
await generateGif ( )
2018-03-30 09:59:16 +02:00
await driver . quit ( )
2018-03-30 09:09:39 +02:00
return
//
// await button.click()
// await delay(700)
// this.seedPhase = await driver.findElement(By.css('.twelve-word-phrase')).getText()
// await captureScreenShot('seed phrase')
//
// const continueAfterSeedPhrase = await driver.findElement(By.css('button'))
// await continueAfterSeedPhrase.click()
// await delay(300)
// await captureScreenShot('main screen')
//
// await driver.findElement(By.css('.sandwich-expando')).click()
// await delay(500)
// await captureScreenShot('menu')
2018-03-30 02:02:40 +02:00
// await driver.findElement(By.css('#app-content > div > div:nth-child(3) > span > div > li:nth-child(3)')).click()
// await captureScreenShot('main screen')
// it('should accept account password after lock', async () => {
// await delay(500)
// await driver.findElement(By.id('password-box')).sendKeys('123456789')
// await driver.findElement(By.css('button')).click()
// await delay(500)
// })
//
// it('should show QR code option', async () => {
// await delay(300)
// 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()
// await delay(300)
// })
//
// it('should show the account address', async () => {
// this.accountAddress = await driver.findElement(By.css('.ellip-address')).getText()
// await driver.findElement(By.css('.fa-arrow-left')).click()
// await delay(500)
// })
2018-03-30 09:48:37 +02:00
async function captureLanguageScreenShots ( label ) {
const nonEnglishLocales = localesIndex . filter ( localeMeta => localeMeta . code !== 'en' )
2018-03-30 09:59:16 +02:00
// take english shot
await captureScreenShot ( ` ${ label } (en) ` )
2018-03-30 09:48:37 +02:00
for ( let localeMeta of nonEnglishLocales ) {
2018-03-30 09:59:16 +02:00
// set locale and take shot
2018-03-30 09:48:37 +02:00
await setLocale ( localeMeta . code )
await delay ( 300 )
await captureScreenShot ( ` ${ label } ( ${ localeMeta . code } ) ` )
}
2018-03-30 09:59:16 +02:00
// return locale to english
2018-03-30 09:48:37 +02:00
await setLocale ( 'en' )
await delay ( 300 )
}
async function setLocale ( code ) {
2018-03-30 20:16:08 +02:00
await driver . executeScript ( 'window.metamask.updateCurrentLocale(arguments[0])' , code )
}
async function setProviderType ( type ) {
await driver . executeScript ( 'window.metamask.setProviderType(arguments[0])' , type )
2018-03-30 09:48:37 +02:00
}
2018-03-30 02:02:40 +02:00
// cleanup
await driver . quit ( )
2018-03-30 09:09:39 +02:00
async function cleanScreenShotDir ( ) {
await pify ( rimraf ) ( ` ./test-artifacts/screens/ ` )
}
2018-03-30 02:02:40 +02:00
async function captureScreenShot ( label ) {
2018-03-30 09:09:39 +02:00
const shotIndex = screenshotCount . toString ( ) . padStart ( 4 , '0' )
2018-03-30 02:02:40 +02:00
screenshotCount ++
const artifactDir = ` ./test-artifacts/screens/ `
await pify ( mkdirp ) ( artifactDir )
// capture screenshot
const screenshot = await driver . takeScreenshot ( )
await pify ( fs . writeFile ) ( ` ${ artifactDir } / ${ shotIndex } - ${ label } .png ` , screenshot , { encoding : 'base64' } )
}
async function generateGif ( ) {
// calculate screenshot size
const screenshot = await driver . takeScreenshot ( )
const pngBuffer = Buffer . from ( screenshot , 'base64' )
const size = sizeOfPng . calculate ( pngBuffer )
2018-03-30 09:59:16 +02:00
// read only the english pngs into gif
2018-03-30 02:02:40 +02:00
const encoder = new GIFEncoder ( size . width , size . height )
2018-03-30 09:59:16 +02:00
const stream = pngFileStream ( './test-artifacts/screens/* (en).png' )
2018-04-03 00:51:00 +02:00
. pipe ( encoder . createWriteStream ( { repeat : 0 , delay : 1000 , quality : 10 } ) )
2018-03-30 09:59:16 +02:00
. pipe ( fs . createWriteStream ( './test-artifacts/screens/walkthrough (en).gif' ) )
2018-03-30 02:02:40 +02:00
// wait for end
await pify ( endOfStream ) ( stream )
}
2018-03-31 00:03:49 +02:00
}
2018-03-30 23:39:43 +02:00
2018-03-31 00:03:49 +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 )
2018-03-30 02:02:40 +02:00
}