How do I pass browser as a command line parameter when launching tests

DarthOpto

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));
    });
},

};

Gunderson

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.

edited at
0

Comments

0 comments
Login to comment

Related

When launching Chrome headless as a command line application process from Java, how do I correctly pass arguments in?

How do I pass a command parameter in a variable holding the command?

How do you control text formatting when launching GAP scripts from the command line?

How can I pass more than 10 command line parameter to jmeter command line run?

How do I pass command line arguments to stack exec

mongodb - how to properly pass a parameter on a command line

How to pass a tempfile as a command line parameter

How to pass parameter to testng in command line?

How do i screenshot chrome browser when my tests fail and before the chrome browser closes (@After)

How to pass command line arguments to tests with gradle test?

How can I pass a command line CONFIG parameter to qmake from QtCreator?

How can I pass parameter in Talend exported job, through command line or bash script file?

How do I pass command to stack GHCi repl from command line

How do I have TestNG run tests in specific groups (from the command-line)?

How do I run nunit 2 tests from nunit-console from the command line?

Launching a web browser from command-line Dart script

How do I launch Tor browser on specific web page from command line?

How do I assign WM_CLASS when launching an application

How do I pass a parameter into a class so that when its parameter is passed in the constructor the JFrame would move?

How do I do this deployment by command line

How to pass parameter to testng xml through command line

How to pass string with double quotes as command line parameter to a batch file

How to pass tablename as parameter to Bigquery command line in shell script

How to pass a command-line ssh parameter with Paramiko?

How to pass parameters to a command in bash when run line by line?

How do you run tests from the command line?

How do I pass a parameter to RazorPage OnGet()?

How do i pass a dictionary as a function parameter?

How do I pass a method as a parameter in Python