diff --git a/README.md b/README.md index 3030d67..6b4f187 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Example config to run Aye Spy: "remoteBucketName": "aye-spy-example", "remoteRegion": "eu-west-1", "limitAmountOfParallelScenarios": 10, // if you are killing your selenium grid use this to batch up scenarios + "onBeforeSuiteScript": "./scripts/login.js", // run a script before the entire suite (this script takes no parameters) "scenarios": [ { "url": "http://thetimes.co.uk/", @@ -84,7 +85,6 @@ Example config to run Aye Spy: ], "waitForElement": "#section-news", // explicitly wait for a selector to be visible before snap "onReadyScript": "./scripts/clickSelector.js", // run a script before snap - "onBeforeSuiteScript": "./scripts/login.js" // run a script before the entire suite (this script takes no parameters) "wait": 2000 // implicitly wait before taking a snap } ] @@ -125,7 +125,7 @@ module.exports = clickElement; In cases where you need to run a script once, before the entire suite is launched (e.g. setting up global objects or setting up external services), pass the path of the script into `onBeforeSuiteScript` in the config file. -Unlike the onReady and onBefore script options, onBeforeSuite script does not have a driver passed to it as an argument. Any external dependencies will need to be set up independantly inside the script. +Unlike the onReady and onBefore script options, onBeforeSuite script does not have a driver passed to it as an argument. Any external dependencies will need to be set up independantly inside the script. However the script does provide access to the config, so that you can read/modify values dynamically if needed. ## Mobile Emulator diff --git a/src/executeScript.js b/src/executeScript.js index 568ca9d..53f8f41 100644 --- a/src/executeScript.js +++ b/src/executeScript.js @@ -8,15 +8,11 @@ const loadFile = script => { return require(path.resolve(script)); // eslint-disable-line }; -export function executeScript(script) { - return execute(script); -} - export function executeScriptWithDriver(driver, script) { - return execute(script, driver, By); + return executeScript(script, driver, By); } -function execute(script, ...params) { +export function executeScript(script, ...params) { return new Promise(async (resolve, reject) => { try { const scriptToExecute = loadFile(script); diff --git a/src/getScreenshots.js b/src/getScreenshots.js index 67660d8..b2b9088 100644 --- a/src/getScreenshots.js +++ b/src/getScreenshots.js @@ -42,8 +42,8 @@ const generateSnapShotPromises = (SnapShotter, config) => { }, []); }; -function executeOnBeforeSuiteScript(scriptPath) { - return executeScript(scriptPath).catch(error => { +function executeOnBeforeSuiteScript(config) { + return executeScript(config.onBeforeSuiteScript, config).catch(error => { throw new Error( `❌ Unable to run onBeforeSuite script:\n due to: ${error}` ); @@ -54,7 +54,7 @@ async function getScreenshots(SnapShotter, config) { return new Promise(async (resolve, reject) => { if (config.onBeforeSuiteScript) { try { - await executeOnBeforeSuiteScript(config.onBeforeSuiteScript); + await executeOnBeforeSuiteScript(config); } catch (error) { onError(); return reject(error); diff --git a/src/getScreenshots.test.js b/src/getScreenshots.test.js index ef3d679..0da14c6 100644 --- a/src/getScreenshots.test.js +++ b/src/getScreenshots.test.js @@ -93,7 +93,8 @@ describe('gets Screenshots', () => { return getScreenshots(MockSnapshotter, config).then(() => { expect(executeScript).toHaveBeenCalledTimes(1); expect(executeScript).toHaveBeenCalledWith( - './src/__mocks__/onBeforeSuiteMock.js' + './src/__mocks__/onBeforeSuiteMock.js', + config ); }); });