Unable to access config.baseUrl configuration in onPrepare section of config
Hi,
I am attempting to conditionally handle some pre-requisite login steps in 1 of 2 ways based on whether or not the config base url (accepted from the command line parameter) is either localhost or www.mydomain.com .
I have consulted a number of the examples in tests and searched back through docs and issue history - but am unable to get the onPrepare function to be able to see the baseUrl parameter despite the docs saying that the ptor instance etc. should be configured / available in this section.
Below is current state of my conf.js -- but I have tried almost every way imaginable or mentioned in the docs to access the baseUrl -- all lead to an baseUrl undefined error.
var exports;
exports.config = {
jasmineNodeOpts: {
onComplete: null,
isVerbose: true,
showColors: true,
includeStackTrace: false,
defaultTimeoutInterval: 30000
},
// sauceUser: 'yyyyyy',
// sauceKey: 'xxxxxxxxxxxxxxxxxxxx',
seleniumJarFile:'selenium-server-standalone-2.44.0.jar',
// Suites can be called like: protractor tests/e2e/protractor.conf.js --suite smoke
suites: {
'smoke': ['smoke.e2e.js'],
'company': ['company*.e2e.js'],
'portfolio': ['portfolio/*.e2e.js']
},
multiCapabilities: [{
'browserName': 'chrome'
}],
onPrepare: function() {
"use strict";
// Check our base url
var _baseUrl;
browser.getProcessedConfig().then(function(config) {
_baseUrl = config.env.baseUrl;
});
console.log('BASE_URL USED IS: '+browser.driver.base);
// Handle live login scenarios
if(String(_baseUrl).split('/').indexOf('mydomain.com') !== -1){
// Do login work for production baseUrl
// Login takes some time, so wait until it's done.
browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /#/.test(url);
});
});
} else {
// Do login work for localhost baseUrl
}
}
};
This is better handled on stackoverflow.com. Please read the contributing guidelines; these types of questions are ill-suited for GitHub. (Apologies to the actual Protractor maintainers if I'm mis-categorizing this one, just trying to help out.)
That said, you're confusing code that looks like its serialized with the promise-land that protractor operates in. (Thus your onPrepare will return before the callbacks have completed, and will thus probably not do exactly what you want....)