为量angular器e2etesting设置环境参数

我们正在使用量angular器来testing我们正在构build的前端angular度应用程序。

目前我们正在使用browser.get()来指定我们希望再次testing的环境(localhost:9000,staging,UAT),但是我想参数化这个,所以当我们使用grunt test:e2etesting来运行我们的testing时grunt test:e2e我们可以指定一个参数将browser.get()更改为指定的环境。

像能够调用grunt test:e2e NODE_ENV=uat来testing指定的环境。

任何人有任何见识如何做到这一点?

您可以将任意数量的parameter passing给量angular器您需要将量angular器任务中的parameter passing给grunt文件。 这里是小片段

 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: {} }, 

你可以像你的规格一样访问参数。 browser.params.fieldName

解决这个问题的常用方法是使用baseUrl命令行参数 :

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

或者,您可以设置webdriver.base.url环境variables :

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

您也可以使用任务pipe理器(例如gruntgrunt-protractor-runner ),并configuration不同的任务在不同的环境下运行testing,设置不同的baseUrl