setting environment parameter for protractor e2e tests

user249656 picture user249656 · May 20, 2015 · Viewed 7.6k times · Source

We are using protractor to test our front end angular app that we are building.

Currently we are using browser.get() to specify our environement we wish to test again(localhost:9000, staging, UAT) however I am wanting to parameterize this so that when we run our tests using grunt test:e2e we can specify a parameter to change the browser.get() to a specified environment.

Something like being able to call grunt test:e2e NODE_ENV=uat to test against specified environment.

Anyone have any insight to how to do this?

Answer

Hasan picture Hasan · May 21, 2015

You can pass any number of arguments to protractor You need to pass parameters within the protractor task in your grunt file. Here is small snippet

config: grunt.file.readJSON('config-param.json'),
protractor: {
        options: {
            configFile: "config/e2e.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.
            debug: '<%= config.debugger %>',
            args: {
                params: '<%= config %>'
            }
        },
        run: {}
    },

and you can access parameters in your specs like. browser.params.fieldName