如何将Gruntfile.js中的参数传递到webdriverio规范
How to pass parameters from the Gruntfile.js to the webdriverio spec?
我想从Gruntfile.js中参数化我的webdriverio规范。目标是在Grunt中指定主机、端口、用户名、密码以及其他参数,并从规范文件中读取它们。
阅读Source Labs的示例https://www.npmjs.com/package/grunt-webdriver#overview我在选项中设置了主机和端口。但是当配置端口时,我得到了以下错误:
/Users/sandro/Developing/Projekte/sling/svn/contrib/explorers/resourceeditor/frontend/node_modules/grunt-webdriver/node_modules/webdriverio/lib/utils/PromiseHandler.js:154
throw error;
RuntimeError: RuntimeError
这就是为什么我认为必须有其他方法来做到这一点。我的Gruntfile.js是这样的:
module.exports = function(grunt) {
var e2eTestSpecFolder = '../src/test/javascript/e2e/spec/**/*spec.js';
grunt.initConfig({
...
webdriver: {
options: {
host: 'localhost',
port: 8080
},
chrome: {
tests: [e2eTestSpecFolder],
options: {
// overwrite default settings
desiredCapabilities: {
browserName: 'chrome'
}
}
},
firefox: {
tests: [e2eTestSpecFolder],
options: {
// overwrite default settings
desiredCapabilities: {
browserName: 'firefox'
}
}
}
}
})
...
grunt.registerTask('desktop_build', ['webdriver:chrome', 'webdriver:firefox']);
};
提前感谢您的任何提示!
更新:我使用以下版本:
grunt cli:v0.1.13
咕哝:v0.4.5
网络驱动程序管理器:3.0.0
grunt网络驱动程序:0.4.8
好的,我解决了你的问题:)
这些"主机"answers"端口"参数是预定义的参数,用于另一个目的(将执行测试的主机和端口,您正在重新定义端口-这就是它们失败的原因,例如这里-https://github.com/webdriverio/webdriverio/blob/master/examples/webdriverio.saucelabs.js你可以看到他们正在使用连接到炖锅实验室)。为此,最简单的解决方案是定义ENV变量并为它们设置一些默认值(但不应该在gruntfile中这样做——事实上,这不是必要的)您可以在第一次放置这些变量的文件中定义它,例如:
testHost: (typeof(process.env.TEST_HOST) === 'undefined') ? 'http://localhost' : process.env.TEST_HOST;
之后,如果需要TEST_HOST作为env变量,您只需提供它:
Linux: sh~ TEST_HOST=http://google.com
grunt task
Win: export TEST_HOST=http://google.com
grunt task
如果不设置变量,则"http://localhost"将是默认值。
相关文章:
- 函数未将值作为参数传递
- 如何将参数传递到angularJs中的工厂
- 如何在HTML元素上创建函数,而不是将元素作为参数传递
- JavaScript常量-作为参数传递或直接使用
- 如何将javascript对象作为参数传递到c#web服务中
- 将参数传递给函数
- 如何将Gruntfile.js中的参数传递到webdriverio规范
- javascript,将参数传递给函数内部的闭包中的回调
- Javascript-将包含变量的html字符串作为参数传递
- 将字符串作为参数传递给函数onclick event jquery
- 将修改后的数组作为参数传递给函数
- 在嵌套递归指令中将参数传递给父控制器方法
- each()-将额外的参数传递给回调参数
- 代码气味-将布尔控制参数传递给函数
- 如何将自定义参数传递到FullCalendar事件提要
- 将参数传递给函数,同时保留事件处理程序
- 将图标作为参数传递不会;t工作-谷歌地图
- 如何使用按钮将参数传递给函数
- 如何将多个参数传递给输入's onChange处理程序
- 是否可以在 Javascript 中将未声明的变量作为参数传递