From e4bcbb6e5e09b38704967cac450a611d12484852 Mon Sep 17 00:00:00 2001 From: mdcruz Date: Mon, 25 Jun 2018 16:13:39 +0100 Subject: [PATCH 1/4] feat: support to execute selenium scripts --- src/__mocks__/seleniumMock.js | 8 +++ src/getScreenshots.js | 4 +- src/snapshotter.js | 24 +++++++- src/snapshotter.test.js | 16 +++++ yarn.lock | 111 ++-------------------------------- 5 files changed, 56 insertions(+), 107 deletions(-) create mode 100644 src/__mocks__/seleniumMock.js diff --git a/src/__mocks__/seleniumMock.js b/src/__mocks__/seleniumMock.js new file mode 100644 index 0000000..e98b21f --- /dev/null +++ b/src/__mocks__/seleniumMock.js @@ -0,0 +1,8 @@ +/* globals jest */ +/* eslint-disable no-unused-vars */ + +const seleniumMockFunction = jest + .fn() + .mockImplementation(driver => Promise.resolve()); + +module.exports = seleniumMockFunction; diff --git a/src/getScreenshots.js b/src/getScreenshots.js index deb10c4..c64cadf 100644 --- a/src/getScreenshots.js +++ b/src/getScreenshots.js @@ -20,7 +20,9 @@ export default (SnapShotter, config) => cookies: scenario.cookies, removeSelectors: scenario.removeSelectors, waitForSelector: scenario.waitForSelector, - url: scenario.url + url: scenario.url, + onBeforeScript: scenario.onBeforeScript, + onReadyScript: scenario.onReadyScript }, { webdriver, By, until } ); diff --git a/src/snapshotter.js b/src/snapshotter.js index f772e1b..d67df23 100644 --- a/src/snapshotter.js +++ b/src/snapshotter.js @@ -1,4 +1,7 @@ +/* eslint-disable import/no-dynamic-require*/ + import fs from 'fs'; +import path from 'path'; import logger from './logger'; export default class SnapShotter { @@ -14,7 +17,9 @@ export default class SnapShotter { removeSelectors, waitForSelector, url = 'http://localhost:80', - viewportLabel = 'viewportLabel' + viewportLabel = 'viewportLabel', + onBeforeScript, + onReadyScript }, selenium ) { @@ -28,6 +33,8 @@ export default class SnapShotter { this._removeSelectors = removeSelectors; this._waitForSelector = waitForSelector; this._url = url; + this._onBeforeScript = onBeforeScript; + this._onReadyScript = onReadyScript; this._viewportLabel = viewportLabel; this._By = selenium.By; this._until = selenium.until; @@ -94,12 +101,25 @@ export default class SnapShotter { } } + async executeScript(script) { + try { + const scriptToExecute = require(path.resolve(script)); + await scriptToExecute(this._driver); + } catch (error) { + logger.error( + 'snapshotter', + `❌ Unable to find the specified script location! ❌ ${error}` + ); + } + } + async takeSnap() { try { logger.info( 'Snapshotting', `${this._label}-${this._viewportLabel} : Url: ${this._url}` ); + if (this._onBeforeScript) await this.executeScript(this._onBeforeScript); await this.driver.get(this._url); if (this._cookies) await this.applyCookies(); @@ -108,6 +128,8 @@ export default class SnapShotter { if (this._removeSelectors) await this.removeTheSelectors(); + if (this._onReadyScript) await this.executeScript(this._onReadyScript); + fs.writeFileSync( `${this._latest}/${this._label}-${this._viewportLabel}.png`, await this.driver.takeScreenshot(), diff --git a/src/snapshotter.test.js b/src/snapshotter.test.js index 43e031e..7f71264 100644 --- a/src/snapshotter.test.js +++ b/src/snapshotter.test.js @@ -1,6 +1,7 @@ /* globals jest expect */ import webdriver, { By, until } from './__mocks__/selenium-webdriver'; import SnapShotter from './snapshotter'; +import jestFunction from './__mocks__/seleniumMock'; jest.mock('fs'); @@ -124,4 +125,19 @@ describe('The snapshotter', () => { await mockSnapshot.takeSnap(); expect(mockSnapshot.driver.addCookie.mock.calls.length).toBe(2); }); + + it('Executes a script', async () => { + const config = { + gridUrl: 'https://lol.com', + url: 'http://cps-render-ci.elb.tnl-dev.ntch.co.uk/', + label: '1homepage', + onBeforeScript: './src/__mocks__/seleniumMock.js', + onReadyScript: './src/__mocks__/seleniumMock.js' + }; + + const mockSnapshot = new SnapShotter(config, { webdriver, By, until }); + await mockSnapshot.takeSnap(); + expect(jestFunction).toBeCalledWith(mockSnapshot.driver); + expect(jestFunction.mock.calls.length).toBe(2); + }); }); diff --git a/yarn.lock b/yarn.lock index f64a1a3..09c2042 100644 --- a/yarn.lock +++ b/yarn.lock @@ -864,13 +864,6 @@ binary-extensions@^1.0.0: version "1.11.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205" -bl@^1.0.0: - version "1.2.2" - resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c" - dependencies: - readable-stream "^2.3.5" - safe-buffer "^5.1.1" - bluebird@^3.0.6: version "3.5.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" @@ -928,25 +921,6 @@ bser@^2.0.0: dependencies: node-int64 "^0.4.0" -buffer-alloc-unsafe@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0" - -buffer-alloc@^1.1.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/buffer-alloc/-/buffer-alloc-1.2.0.tgz#890dd90d923a873e08e10e5fd51a57e5b7cce0ec" - dependencies: - buffer-alloc-unsafe "^1.1.0" - buffer-fill "^1.0.0" - -buffer-crc32@~0.2.3: - version "0.2.13" - resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" - -buffer-fill@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c" - buffer-from@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.0.tgz#87fcaa3a298358e0ade6e442cfce840740d1ad04" @@ -1380,16 +1354,6 @@ cross-spawn@^5.0.1, cross-spawn@^5.1.0: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^6.0.0: - version "6.0.5" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" - dependencies: - nice-try "^1.0.4" - path-key "^2.0.1" - semver "^5.5.0" - shebang-command "^1.2.0" - which "^1.2.9" - cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0": version "0.3.2" resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b" @@ -1436,7 +1400,7 @@ debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: dependencies: ms "2.0.0" -debug@^3.0.0, debug@^3.1.0: +debug@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" dependencies: @@ -1963,12 +1927,6 @@ fb-watchman@^2.0.0: dependencies: bser "^2.0.0" -fd-slicer@~1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e" - dependencies: - pend "~1.2.0" - figures@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" @@ -2091,10 +2049,6 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" -fs-constants@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" - fs-exists-sync@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add" @@ -4001,10 +3955,6 @@ nested-error-stacks@^1.0.0: dependencies: inherits "~2.0.1" -nice-try@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.4.tgz#d93962f6c52f2c1558c0fbda6d512819f1efe1c4" - node-emoji@^1.4.1: version "1.8.1" resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.8.1.tgz#6eec6bfb07421e2148c75c6bba72421f8530a826" @@ -4353,7 +4303,7 @@ path-is-inside@^1.0.1, path-is-inside@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" -path-key@^2.0.0, path-key@^2.0.1: +path-key@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" @@ -4381,10 +4331,6 @@ path-type@^3.0.0: dependencies: pify "^3.0.0" -pend@~1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" - performance-now@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" @@ -4491,7 +4437,7 @@ process-nextick-args@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa" -progress@2.0.0, progress@^2.0.0: +progress@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f" @@ -4722,7 +4668,7 @@ read-pkg@^3.0.0: isarray "0.0.1" string_decoder "~0.10.x" -readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.0, readable-stream@^2.3.5: +readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2: version "2.3.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" dependencies: @@ -4883,7 +4829,7 @@ request-promise-native@^1.0.5: stealthy-require "^1.1.0" tough-cookie ">=2.3.3" -request@2.87.0, request@^2.83.0: +request@^2.83.0: version "2.87.0" resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e" dependencies: @@ -5050,24 +4996,6 @@ sax@>=0.6.0, sax@^1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" -selenium-standalone@^6.15.0: - version "6.15.0" - resolved "https://registry.yarnpkg.com/selenium-standalone/-/selenium-standalone-6.15.0.tgz#c8dc77bd45154afbda7509ec53dc599809f63ee4" - dependencies: - async "^2.1.4" - commander "^2.9.0" - cross-spawn "^6.0.0" - debug "^3.0.0" - lodash "^4.17.4" - minimist "^1.2.0" - mkdirp "^0.5.1" - progress "2.0.0" - request "2.87.0" - tar-stream "1.6.1" - urijs "^1.18.4" - which "^1.2.12" - yauzl "^2.5.0" - selenium-webdriver@^4.0.0-alpha.1: version "4.0.0-alpha.1" resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.0.0-alpha.1.tgz#cc93415e21d2dc1dfd85dfc5f6b55f3ac53933b1" @@ -5455,18 +5383,6 @@ table@4.0.2: slice-ansi "1.0.0" string-width "^2.1.1" -tar-stream@1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-1.6.1.tgz#f84ef1696269d6223ca48f6e1eeede3f7e81f395" - dependencies: - bl "^1.0.0" - buffer-alloc "^1.1.0" - end-of-stream "^1.0.0" - fs-constants "^1.0.0" - readable-stream "^2.3.0" - to-buffer "^1.1.0" - xtend "^4.0.0" - tar@^4: version "4.4.4" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.4.tgz#ec8409fae9f665a4355cc3b4087d0820232bb8cd" @@ -5550,10 +5466,6 @@ tmpl@1.0.x: version "1.0.4" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" -to-buffer@^1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/to-buffer/-/to-buffer-1.1.1.tgz#493bd48f62d7c43fcded313a03dcadb2e1213a80" - to-fast-properties@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" @@ -5676,10 +5588,6 @@ update-notifier@^0.2.2: semver-diff "^2.0.0" string-length "^1.0.0" -urijs@^1.18.4: - version "1.19.1" - resolved "https://registry.yarnpkg.com/urijs/-/urijs-1.19.1.tgz#5b0ff530c0cbde8386f6342235ba5ca6e995d25a" - urix@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" @@ -5921,7 +5829,7 @@ xmlbuilder@~9.0.1: version "9.0.7" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d" -"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0, xtend@~4.0.1: +"xtend@>=4.0.0 <4.1.0-0", xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" @@ -5968,10 +5876,3 @@ yargs@~3.10.0: cliui "^2.1.0" decamelize "^1.0.0" window-size "0.1.0" - -yauzl@^2.5.0: - version "2.9.2" - resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.9.2.tgz#4fb1bc7ae1fc2f57037b54af6acc8fe1031c5b77" - dependencies: - buffer-crc32 "~0.2.3" - fd-slicer "~1.1.0" From 5d0712ec48ea489bec4d3999228ec1d14e60ae0d Mon Sep 17 00:00:00 2001 From: mdcruz Date: Mon, 25 Jun 2018 16:34:57 +0100 Subject: [PATCH 2/4] refactor: amended variable name --- src/snapshotter.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/snapshotter.test.js b/src/snapshotter.test.js index 7f71264..d1e781d 100644 --- a/src/snapshotter.test.js +++ b/src/snapshotter.test.js @@ -1,7 +1,7 @@ /* globals jest expect */ import webdriver, { By, until } from './__mocks__/selenium-webdriver'; import SnapShotter from './snapshotter'; -import jestFunction from './__mocks__/seleniumMock'; +import seleniumMockFunction from './__mocks__/seleniumMock'; jest.mock('fs'); @@ -137,7 +137,7 @@ describe('The snapshotter', () => { const mockSnapshot = new SnapShotter(config, { webdriver, By, until }); await mockSnapshot.takeSnap(); - expect(jestFunction).toBeCalledWith(mockSnapshot.driver); - expect(jestFunction.mock.calls.length).toBe(2); + expect(seleniumMockFunction).toBeCalledWith(mockSnapshot.driver); + expect(seleniumMockFunction.mock.calls.length).toBe(2); }); }); From 839e30eccba97b4dd324307c5d26d1a1de060c88 Mon Sep 17 00:00:00 2001 From: Marie Cruz Date: Tue, 26 Jun 2018 17:18:33 +0100 Subject: [PATCH 3/4] refactor: addressed PR comments --- README.md | 35 +++++++++++++++++++++++++--------- src/__mocks__/seleniumMock.js | 3 +-- src/snapshotter.js | 12 +++++------- src/snapshotter.test.js | 36 ++++++++++++++++++++++++++++++----- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7497858..8fccd46 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Aye Spy + ### Aye Spy with my little eye... a visual regression! Aye spy is a high performance visual regression tool. Created to fit in with your cloud infrastructure and distribute tests using selenium grid for huge performance gains. In order to get the most out of Aye Spy we recommend using a selenium grid and cloud storage (currently supporting Amazon S3). However if you wish to run locally that is also supported but the performance gains will be less significant. - ## Inspiration -We have taken inspiration for this project from existing projects such as Wraith and BackstopJs. +We have taken inspiration for this project from existing projects such as Wraith and BackstopJs. Visual regressions testing is a great tool to have in your pipeline but the current solutions on the market were missing one key component we felt was essential for a great developer experience... performance! @@ -20,7 +20,7 @@ With the correct set up you can expect your tests using aye-spy to take under a To install the package: -```npm i -g aye-spy``` +`npm i -g aye-spy` In order to use the remote functionality you will need to export some aws credentials: @@ -31,7 +31,7 @@ export AWS_ACCESS_KEY_ID=keyid Create an S3 bucket to store your images. It will also need to have the correct permissions set up. -Example cofig: +Example config: ``` { @@ -54,12 +54,31 @@ Example cofig: "value": "cookie_value" } ], - "waitForSelector": ["#section-news"] + "waitForSelector": ["#section-news"], + "onReadyScript": './scripts/clickSelector.js' } ] } - ``` +``` + +## Custom Scripts +For scenarios where you need to interact with the page before taking a screenshot, a custom script can be used which contains the selenium webdriver actions. The onReadyScript property takes a string path to the the script to be executed. + +Only es5 is currently supported so please transpile. + +Example script: + +``` +const By = require('selenium-webdriver').By; + +const clickElement = async browser => { + await browser.findElement(By.css('#buttonId"]')).click(); + ); +}; + +module.exports = clickElement; +``` ## Running @@ -75,8 +94,6 @@ Run the comparison: `ayespy compare --browser chrome --config config.json --remote` -Generate the comparison report: +Generate the comparison report: `ayespy generate-report --browser chrome --config config.json --remote` - - diff --git a/src/__mocks__/seleniumMock.js b/src/__mocks__/seleniumMock.js index e98b21f..bab5080 100644 --- a/src/__mocks__/seleniumMock.js +++ b/src/__mocks__/seleniumMock.js @@ -1,8 +1,7 @@ /* globals jest */ -/* eslint-disable no-unused-vars */ const seleniumMockFunction = jest .fn() - .mockImplementation(driver => Promise.resolve()); + .mockImplementation(driver => Promise.resolve()); //eslint-disable-line no-unused-vars module.exports = seleniumMockFunction; diff --git a/src/snapshotter.js b/src/snapshotter.js index d67df23..a942499 100644 --- a/src/snapshotter.js +++ b/src/snapshotter.js @@ -106,10 +106,7 @@ export default class SnapShotter { const scriptToExecute = require(path.resolve(script)); await scriptToExecute(this._driver); } catch (error) { - logger.error( - 'snapshotter', - `❌ Unable to find the specified script location! ❌ ${error}` - ); + logger.error('snapshotter', `❌ Unable to run script due to: ${error}`); } } @@ -119,17 +116,18 @@ export default class SnapShotter { 'Snapshotting', `${this._label}-${this._viewportLabel} : Url: ${this._url}` ); - if (this._onBeforeScript) await this.executeScript(this._onBeforeScript); await this.driver.get(this._url); + if (this._onBeforeScript) await this.executeScript(this._onBeforeScript); + if (this._cookies) await this.applyCookies(); if (this._waitForSelector) await this.waitForSelector(); - if (this._removeSelectors) await this.removeTheSelectors(); - if (this._onReadyScript) await this.executeScript(this._onReadyScript); + if (this._removeSelectors) await this.removeTheSelectors(); + fs.writeFileSync( `${this._latest}/${this._label}-${this._viewportLabel}.png`, await this.driver.takeScreenshot(), diff --git a/src/snapshotter.test.js b/src/snapshotter.test.js index d1e781d..ad10ee2 100644 --- a/src/snapshotter.test.js +++ b/src/snapshotter.test.js @@ -1,7 +1,8 @@ /* globals jest expect */ import webdriver, { By, until } from './__mocks__/selenium-webdriver'; import SnapShotter from './snapshotter'; -import seleniumMockFunction from './__mocks__/seleniumMock'; +import seleniumMock from './__mocks__/seleniumMock'; +import logger from './logger'; jest.mock('fs'); @@ -126,18 +127,43 @@ describe('The snapshotter', () => { expect(mockSnapshot.driver.addCookie.mock.calls.length).toBe(2); }); - it('Executes a script', async () => { + it('Executes the onBefore script', async () => { + const config = { + gridUrl: 'https://lol.com', + url: 'http://cps-render-ci.elb.tnl-dev.ntch.co.uk/', + label: '1homepage', + onBeforeScript: './src/__mocks__/seleniumMock.js' + }; + + const mockSnapshot = new SnapShotter(config, { webdriver, By, until }); + await mockSnapshot.takeSnap(); + expect(seleniumMock).toBeCalledWith(mockSnapshot.driver); + }); + + it('Executes the onReady script', async () => { const config = { gridUrl: 'https://lol.com', url: 'http://cps-render-ci.elb.tnl-dev.ntch.co.uk/', label: '1homepage', - onBeforeScript: './src/__mocks__/seleniumMock.js', onReadyScript: './src/__mocks__/seleniumMock.js' }; const mockSnapshot = new SnapShotter(config, { webdriver, By, until }); await mockSnapshot.takeSnap(); - expect(seleniumMockFunction).toBeCalledWith(mockSnapshot.driver); - expect(seleniumMockFunction.mock.calls.length).toBe(2); + expect(seleniumMock).toBeCalledWith(mockSnapshot.driver); + }); + + it.only('Throws an error if incorrect script file is provided', async () => { + const config = { + gridUrl: 'https://lol.com', + url: 'http://cps-render-ci.elb.tnl-dev.ntch.co.uk/', + label: '1homepage', + onReadyScript: '/brokenfile.js' + }; + + logger.error = jest.fn(); + const mockSnapshot = new SnapShotter(config, { webdriver, By, until }); + await mockSnapshot.takeSnap(); + expect(logger.error.mock.calls.length).toBe(1); }); }); From 1207156e1bbedfe359bba4c804ab5c44326fd282 Mon Sep 17 00:00:00 2001 From: Marie Cruz Date: Wed, 27 Jun 2018 09:41:36 +0100 Subject: [PATCH 4/4] fix: syntax error in readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8fccd46..72dedeb 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,6 @@ const By = require('selenium-webdriver').By; const clickElement = async browser => { await browser.findElement(By.css('#buttonId"]')).click(); - ); }; module.exports = clickElement;