I'm using BrowserStack to run my test automation - there is a config example on their site to set up 'commonCapabilities'.
I know this is basic JS but what's the use for the double pipe within this for loop?
// Code to support common capabilities
exports.config.multiCapabilities.forEach(function(caps){
for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
});
The full config:
https://www.browserstack.com/automate/protractor
exports.config = {
'seleniumAddress': 'http://hub-cloud.browserstack.com/wd/hub',
'commonCapabilities': {
'browserstack.user': 'xxxx',
'browserstack.key': 'xxxx'
},
'multiCapabilities': [{
'browserName': 'Chrome'
},{
'browserName': 'Safari'
},{
'browserName': 'Firefox'
},{
'browserName': 'IE'
}]
};
// Code to support common capabilities
exports.config.multiCapabilities.forEach(function(caps){
for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
});
It's an expression that is more easily read like so:
Which means return
caps[i]
if it can be converted to true; otherwise, returnexports.config.commonCapabilities[i]
. Ifcaps[i]
is undefined, as that's a falsey value, it'll set the variable toexports.config.commonCapabilities[i]
. It's a way of making sure each is defined, otherwise fallback to some standard config.