为 Protractor e2e 测试设置环境参数
setting environment parameter for protractor e2e tests
我们正在使用量角器来测试我们正在构建的前端 angular 应用程序。
目前我们正在使用 browser.get()
来指定我们希望再次测试的环境(本地主机:9000,暂存,UAT)但是我想参数化它以便当我们 运行 我们的测试使用 grunt test:e2e
我们可以指定一个参数来将 browser.get()
更改为指定的环境。
比如能够调用 grunt test:e2e NODE_ENV=uat
来针对指定环境进行测试。
有人知道如何做到这一点吗?
解决问题的常用方法是使用 baseUrl
command-line argument:
protractor --baseUrl='http://localhost:9000' protractor.conf.js
或者,您可以设置 webdriver.base.url
environment variable:
webdriver.base.url=http://localhost:9000
您还可以使用任务管理器(例如 grunt
和 grunt-protractor-runner
)并在不同的环境设置不同的 baseUrl
中为 运行 测试配置不同的任务。
您可以将任意数量的参数传递给量角器
您需要在 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
我们正在使用量角器来测试我们正在构建的前端 angular 应用程序。
目前我们正在使用 browser.get()
来指定我们希望再次测试的环境(本地主机:9000,暂存,UAT)但是我想参数化它以便当我们 运行 我们的测试使用 grunt test:e2e
我们可以指定一个参数来将 browser.get()
更改为指定的环境。
比如能够调用 grunt test:e2e NODE_ENV=uat
来针对指定环境进行测试。
有人知道如何做到这一点吗?
解决问题的常用方法是使用 baseUrl
command-line argument:
protractor --baseUrl='http://localhost:9000' protractor.conf.js
或者,您可以设置 webdriver.base.url
environment variable:
webdriver.base.url=http://localhost:9000
您还可以使用任务管理器(例如 grunt
和 grunt-protractor-runner
)并在不同的环境设置不同的 baseUrl
中为 运行 测试配置不同的任务。
您可以将任意数量的参数传递给量角器 您需要在 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