onPrepare: require('./capabilities.js'),
if (browser.inOSX()) {
// in Mac...
} else if (browser.inWindows()) {
// in Windows...
} else {
// likely in Linux...
}
//////////////////////////////////////////////// | |
// Protractor Browser Capabilities Extensions // | |
//////////////////////////////////////////////// | |
"use strict"; | |
module.exports = browser.getCapabilities().then(function(s) { | |
var browserName, browserVersion; | |
var shortName, shortVersion; | |
var ie, ff, ch, sa; | |
var platform; | |
platform = s.caps_.platform; | |
browserName = s.caps_.browserName; | |
browserVersion = s.caps_.version; | |
shortVersion = browserVersion.split('.')[0]; | |
ie = /i.*explore/.test(browserName); | |
ff = /firefox/.test(browserName); | |
ch = /chrome/.test(browserName); | |
sa = /safari/.test(browserName); | |
if (ie) { | |
shortName = 'ie'; | |
} else if (ff) { | |
shortName = 'ff'; | |
} else if (ch) { | |
shortName = 'ch'; | |
} else if (sa) { | |
shortName = 'sa'; | |
} else { | |
throw new Exception('Unsupported browser: '+ browserName); | |
}; | |
// Returns one of these: ['ch', 'ff', 'sa', 'ie'] | |
browser.getShortBrowserName = function() { | |
return shortName; | |
}; | |
// Returns one of these: ['ch33', 'ff27', 'sa7', 'ie11', 'ie10', 'ie9'] | |
browser.getShortNameVersionAll = function() { | |
return shortName + shortVersion; | |
}; | |
// Returns one of these: ['ch', 'ff', 'sa', 'ie11', 'ie10', 'ie9'] | |
browser.getShortNameVersion = function() { | |
if (ie) { | |
return shortName + shortVersion; | |
} else { | |
return shortName; | |
}; | |
}; | |
// Return if current browser is IE, optionally specifying if it is a particular IE version | |
browser.isInternetExplorer = function(ver) { | |
if (ver == null) { | |
return ie; | |
} else { | |
return ie && ver.toString() === shortVersion; | |
} | |
}; | |
// Function alias | |
browser.isIE = browser.isInternetExplorer; | |
browser.isSafari = function() { | |
return sa; | |
}; | |
browser.isFirefox = function() { | |
return ff; | |
}; | |
// Return if current browser is Chrome, optionally specifying if it is a particular Chrome version | |
browser.isChrome = function(ver) { | |
if (ver == null) { | |
return ch; | |
} else { | |
return ch && ver.toString() === shortVersion; | |
} | |
}; | |
browser.inWindows = function() { | |
return /^WIN|XP/.test(platform); | |
}; | |
browser.inOSX = function() { | |
return /^MAC/.test(platform); | |
}; | |
// Save current webdriver session id for later use | |
browser.webdriverRemoteSessionId = s.caps_['webdriver.remote.sessionid']; | |
browser.inSauceLabs = function() { | |
return !!(browser.params.inSauceLabs); | |
}; | |
browser.inBrowserStack = function() { | |
return !!(browser.params.inBrowserStack); | |
}; | |
browser.inTheCloud = function() { | |
return !!(browser.params.inSauceLabs || browser.params.inBrowserStack); | |
}; | |
}); |
Help. I tried using this EXACTLY as shown and I get the following error:
ERROR - failed loading configuration file ./protractor.conf.js
/usr/local/bin/node_modules/protractor/lib/configParser.js:183
throw e;
^
ReferenceError: browser is not defined
at Object.<anonymous> (/Users/jonrosen/repo/gyft-b2b-webapp/test/capabilities.js:3:18)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/jonrosen/repo/gyft-b2b-webapp/test/protractor.conf.js:21:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
This is a pretty "early" failure and it is based on the fact that your supplied function uses the "browser" global reference in the very first functional line. My config file is
exports.config = {
jasmineNodeOpts: {
isVerbose: true,
defaultTimeoutInterval: 120000
},
allScriptsTimeout: 120000,
getPageTimeout: 60000,
seleniumAddress: "http://localhost:4444/wd/hub",
specs: ["e2e/specs/login-spec.js",
"e2e/specs/send-to-one-spec.js",
"e2e/specs/upload-spec.js",
"e2e/specs/reset-pswd-spec.js"],
multiCapabilities: [
//{browserName: "chrome"},
{browserName: "firefox",
firefox_binary: "/Applications/Firefox.app/Contents/MacOS/firefox",
binary_: "/Applications/Firefox.app/Contents/MacOS/firefox"
}
],
onPrepare: require('./capabilities.js'),
};
Unless you have left something very important out of your description, this is what you said to do and it should work. But it doesn't.
Any thoughts? Thanks...
This may fail JSHint (depending on your configuration) due to:
It'd be nice if these were fixed up :)