Environmental parameter for e2e protractor tests

We use protractor to test our external angular application that we are creating.

We are currently using browser.get() to indicate our environment that we want to check again (localhost: 9000, staging, UAT), however I want to parameterize it so that when we run our tests with grunt test:e2e we can specify a parameter to change browser.get() to the specified environment.

Something like calling grunt test:e2e NODE_ENV=uat to test the specified environment.

Does anyone have an idea on how to do this?

+6
source share
2 answers

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

 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 the parameters in your specifications. browser.params.fieldName

+7
source

A common way to solve 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 webdriver.base.url :

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

You can also use the task manager (for example, grunt and grunt-protractor-runner ) and configure various tasks to run tests in another setting for the baseUrl s environment.

+4
source

Source: https://habr.com/ru/post/987597/


All Articles