我将下面的代码用于 Protractor 配置文件中使用的参数
protractor: {
options: {
keepAlive: true,
configFile: "test/config.js",
args:{
params:{
user:"user1",
password:"password1"
}
}
},
并在 Protractor conf 文件中检索为 browser.params.user,browser.params.password
这些是工作文件。 我想从命令更改用户和密码值。 如何更改值?
最佳答案
这是一个简单的解决方法:
当您将参数传递给您的 grunt 任务时:
grunt e2e --user=alex --password=password
它可以作为
grunt.option('user')
然后您可以使用以下方法编辑配置中的值:
var protConfig = grunt.config.get('protractor');
protConfig.options['someKey']=newValue;
grunt.config('protractor', protConfig);
grunt.task.run('protractor');
不确定这是解决问题的最佳方法,但它对我来说工作正常。 另请注意,我们正在包装 Protractor 任务,而不是立即调用它
关于javascript - 无法将参数从命令传递到 grunt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26030996/