Skip to content

Commit

Permalink
added some error checking around eyes integration logic to fix john-d…
Browse files Browse the repository at this point in the history
…oherty#42 - if this fails, we need to back it out
  • Loading branch information
John Doherty committed Oct 3, 2017
1 parent 23a307f commit 48465ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ function collectPaths(value, paths) {
}

function coerceInt(value, defaultValue) {

var int = parseInt(value);

if (typeof int == 'number') {
return int;
}
else {
return defaultValue;
}
if (typeof int === 'number') return int;

return defaultValue;
}

var config = {
Expand All @@ -28,7 +26,7 @@ var config = {
sharedObjects: './shared-objects',
reports: './reports',
browser: 'chrome',
timeout: 10000
timeout: 15000
};

var configFileName = path.resolve(process.cwd(), 'selenium-cucumber-js.json');
Expand Down Expand Up @@ -61,7 +59,7 @@ program.on('--help', function () {
global.browserName = program.browser;

// store Eyes Api globally (used within world.js to set Eyes)
global.eyeskey = config.eye_key
global.eyesKey = config.eye_key

// used within world.js to import page objects
global.pageObjectPath = path.resolve(program.pageObjects);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"url": "https://github.com/john-doherty/selenium-cucumber-js/issues"
},
"engines": {
"node": ">= 6.9.0"
"node": "6.11.0"
},
"engineStrict": true,
"homepage": "https://github.com/john-doherty/selenium-cucumber-js#readme",
"dependencies": {
"chai": "3.5.0",
Expand Down
35 changes: 23 additions & 12 deletions runtime/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ function getDriverInstance() {


/**
* Initialize the eyes SDK and set your private API key via the config file.*/
* Initialize the eyes SDK and set your private API key via the config file.
*/
function getEyesInstance() {

var eyes = new Eyes();
if (global.eyesKey) {

//retrieve apikey from config file in the project root as defined by the user
eyes.setApiKey(eyeskey);
var eyes = new Eyes();

return eyes;
// retrieve eyes api key from config file in the project root as defined by the user
eyes.setApiKey(global.eyesKey);

return eyes;
}

return null;
}

function consoleInfo() {
Expand Down Expand Up @@ -136,7 +140,7 @@ function importSupportObjects() {

if (fs.existsSync(itemPath)) {

var dir = requireDir(itemPath, {camelcase: true});
var dir = requireDir(itemPath, { camelcase: true });

merge(allDirs, dir);
}
Expand All @@ -154,7 +158,7 @@ function importSupportObjects() {
if (global.pageObjectPath && fs.existsSync(global.pageObjectPath)) {

// require all page objects using camel case as object names
global.page = requireDir(global.pageObjectPath, {camelcase: true});
global.page = requireDir(global.pageObjectPath, { camelcase: true });
}

// add helpers
Expand All @@ -178,9 +182,10 @@ module.exports = function () {

if (!global.driver || !global.eyes) {
global.driver = getDriverInstance();

// TOOD: this all feels a bit hacky, needs rethinking...
global.eyes = getEyesInstance();
}

});

this.registerHandler('AfterFeatures', function (features, done) {
Expand Down Expand Up @@ -224,11 +229,17 @@ module.exports = function () {

return driver.close().then(function () {
return driver.quit();
}).then(function () {
// If the test was aborted before eyes.close was called ends the test as aborted.
return eyes.abortIfNotClosed();
})
.then(function() {

if (eyes) {
// If the test was aborted before eyes.close was called ends the test as aborted.
return eyes.abortIfNotClosed();
}

return Promise.resolve();
});
})
});
}

return driver.close().then(function () {
Expand Down

0 comments on commit 48465ac

Please sign in to comment.