繁体   English   中英

如何将参数从Gruntfile.js传递到webdriverio规范?

[英]How to pass parameters from the Gruntfile.js to the webdriverio spec?

我想从Gruntfile.js参数化我的webdriverio规格。 目的是在Grunt中指定主机,端口,用户名,密码以及其他参数,然后从规格文件中读取它们。

https://www.npmjs.com/package/grunt-webdriver#overview阅读Source Labs示例我在选项中设置了主机和端口。 但是在配置端口时出现以下错误:

/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

  • 咕unt声:v0.4.5

  • webdriver-manager:3.0.0

  • grunt-webdriver:0.4.8

好的,我有你的问题:)

这些“主机”和“端口”参数是预定义的参数,它们用于另一目的(将在其中执行测试的主机和端口,而您正在重新定义端口-这就是它们失败的原因,例如,在这里- https://github.com/webdriverio/webdriverio/blob/master/examples/webdriverio.saucelabs.js,您可以看到它们正在用于连接到ucelabs。 为此,最简单的解决方案是定义ENV变量并为其设置一些默认值(但实际上,您不必在gruntfile中执行此操作,这不是必需的)。您可以在文件中定义它,将这些变量放置在文件中。第一次像:

testHost: (typeof(process.env.TEST_HOST) === 'undefined') ? 'http://localhost' : process.env.TEST_HOST;

之后,如果需要将它用作环境变量,则只需提供TEST_HOST:

    Linux: sh~ TEST_HOST=http://google.com
grunt task
    Win: export TEST_HOST=http://google.com
grunt task

如果不设置该变量,则默认为“ http:// localhost ”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM