I am trying to run multi-browser testing against Chrome and Firefox. I would like to only run one browser at a time. So I would like to pass into test a command line parameter --browser chrome
for example and have it only run the chrome browser.
I read somewhere that I could do a params: {}
section of my protractor.config.js.
So I added the following:
params: {
browser: multiCapabilities.browserName,
},
The error that I am getting is below:
ReferenceError: multiCapabilities is not defined
at Object.<anonymous> (/Users/csalisbury/src/helios/protractor.config.js:91:18)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at ConfigParser.addFileConfig (/Users/csalisbury/src/helios/node_modules/protractor/built/configParser.js:135:26)
at Object.initFn [as init] (/Users/csalisbury/src/helios/node_modules/protractor/built/launcher.js:93:22)
There is a multiCapabilities
section defined. I also tried this with capabilities
and got the same message.
What am I doing incorrectly here?
Here is my protractor.config.js
exports.config = {
suites: {
<test suites go here>
},
baseUrl: baseUrl,
directConnect: false,
allScriptsTimeout: 25 * 1000,
jasmineNodeOpts: {
defaultTimeoutInterval: 90 * 1000
},
getPageTimeout: 120 * 1000,
capabilities: {
browserName: 'chrome',
seleniumAddress: seleniumServer,
platform: 'ANY',
version: 'ANY',
chromeOptions: {
args: ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'],
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'C:\\downloads\\'
},
},
},
loggingPrefs: { browser: 'SEVERE' }
},
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['--safe-mode'],
binary: '/Applications/Firefox.app/Contents/MacOS/firefox'
},
seleniumAddress: seleniumServer,
},
framework: 'jasmine2',
onPrepare: function() {
//Set Up a JUnit XML Reporter - Makes a nice test results area and trend graph in Jenkins
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'report',
filePrefix: 'xmloutput'
}));
//Setup screenshots
jasmine.getEnv().addReporter(reporter);
browser.get(browser.baseUrl);
},
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve) {
reporter.beforeLaunch(resolve);
});
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve) {
reporter.afterLaunch(resolve.bind(this, exitCode));
});
},
};
browserName
is set using capabilities
- both for command line and in your config. So to set that with command line, it's just:
protractor conf.js --capabilities.browserName='firefox'
Values passed from the command line will override what is set in the config, so for example you could leave chrome as the default browser:
exports.config = {
capabilities: {
browserName: 'chrome'
}
}
And then to override chrome and run firefox, you would just pass in browserName
as shown above.
Or if you want to avoid command line options and just run each browser sequentially, you can use multiCapabilities
and limit the number of maxSessions
allowed.
multiCapabilities: [
{ browserName: 'chrome' },
{ browserName: 'firefox' },
],
maxSessions: 1,
Source: protractor config
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments