setting environment parameter for protractor e2e tests
Asked Answered
N

2

6

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?

Noonan answered 20/5, 2015 at 18:31 Comment(0)
L
8

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

Littman answered 21/5, 2015 at 8:12 Comment(1)
I see that i can put baseUrl: into the params field of the grunt file, however can i have a task runner that specifies the baseUrl to use? Even being able to call browser.params.baseUrl in my specs, this wont help with being able to run tests specific to my environment.Noonan
M
4

The common way to approach the problem is to use baseUrl command-line argument:

protractor --baseUrl='http://localhost:9000' protractor.conf.js

Or, you can set the webdriver.base.url environment variable:

webdriver.base.url=http://localhost:9000

You can also use a task manager (e.g. grunt and grunt-protractor-runner) and configure different tasks for running tests in a different environment setting different baseUrls.

Monosymmetric answered 20/5, 2015 at 21:30 Comment(4)
Thanks for that! I've figured out that I can set the grunt task manager to have something like: else if (target === 'e2euat') { return grunt.task.run([ 'clean:server', 'env:all', 'env:uat', 'concurrent:test', 'injector', 'wiredep', 'autoprefixer', 'express:dev', 'protractor' ]); } However the problem i'm not trying to solve is how to pass in this task to the browser.get() in my spec file for when navigating "home"Noonan
@Noonan whenever you are using browser.get(), use relative to base urls, e.g. browser.get("index.html").Monosymmetric
Thanks! So i think grunt-protractor-runner is the route i should be taking. Fortunately, i noticed that our Gruntfile.js is already referencing protractor where we specify the protractor.config.js file. If i specify the baseUrl: "http://localhost:9000" in protractor.config.js then we are always going to be navigate to localhost rather than a parameterized environment. Is there a way to get the task manager to update the different baseUrl's? I dont see anything in the docs that i've read through:\ Maybe a way to say baseUATUrl:?Noonan
Hi, can anyone guide on how to set baseUrl using gulp taskCetinje

© 2022 - 2024 — McMap. All rights reserved.