How do I parameterize the baseUrl property of the protractor config file

Seems like this is already possible, but the documentation is spotty in this area. Looking at the code, however, protractor does support a number of seemingly undocumented command line arguments.

So, running something like this will work:

protractor --baseUrl='http://some.server.com' my.conf.js

The other option is to use gruntfile.js and have it call the protractor config file.

//gruntfile.js

module.exports = function (grunt) {
    grunt.registerTask("default", "", function () {
    });

    //Configure main project settings
    grunt.initConfig({
        //Basic settings and infor about our plugins
        pkg: grunt.file.readJSON('package.json'),

        //Name of plugin
        cssmin: {
        },

        protractor: {
            options: {
                configFile: "conf.js", // Default config file
                keepAlive: true, // If false, the grunt process stops when the test fails.
                noColor: false, // If true, protractor will not use colors in its output.
                args: {
                    baseUrl: grunt.option('baseUrl') || 'http://localhost:6034/'
                }
            },
            your_target: {   // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
                options: {
                    configFile: "conf.js", // Target-specific config file
                    args: {
                        baseUrl: grunt.option('baseUrl') || 'http://localhost:63634/'
                    }
                }
            },
        },

        //uglify
        uglify: {
        }
    });

    //Load the plugin
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-protractor-runner');

    //Do the Task
    grunt.registerTask('default', ['cssmin']);
};

the Protractor config file: conf.js

exports.config = {
    directConnect: true,

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'chrome',
        'chromeOptions': {
            args: ['--no-sandbox']
        }
    },

    chromeOnly: true,

    // Framework to use. Jasmine is recommended.
    framework: 'jasmine',

    // Spec patterns are relative to the current working directory when
    // protractor is called.
    specs: ['specs/*/*_spec.js'],

    suites : {
      abcIdentity : 'specs/abcIdentity/*_spec.js'  //picks up all the _spec.js files
    },

    params: {
        UserName: '[email protected]',
        Password: '123'
    },

    // Options to be passed to Jasmine.
    jasmineNodeOpts: {
        defaultTimeoutInterval: 30000,
        includeStackTrace: true
    },

    onPrepare: function () {
        browser.driver.manage().window().maximize();
        if (process.env.TEAMCITY_VERSION) {
            var jasmineReporters = require('jasmine-reporters');
            jasmine.getEnv().addReporter(new jasmineReporters.TeamCityReporter());
        }
    }
};

//To run with default url http://localhost:6034

grunt protractor

//To run with any other url

grunt protractor --baseUrl:"http://dev.abc.com/"

Tags:

Protractor