将WebdriverIO'spec'测试作为节点文件运行

时间:2015-10-23 21:33:25

标签: webdriver-io

我是webdriverio的新手。我不明白它应该如何在节点应用程序中配置和使用。 如何在导入webdriverio时运行'spec'测试?可以吗?

// based on http://webdriver.io/guide.html
var webdriverio = require('webdriverio');
var options = {
    desiredCapabilities: {
        browserName: 'firefox'
    },
    specs: './test/spec/**' // why doesn't this work, when it would work when run from the wdio cli
};

webdriverio
    .remote(options)
    .init()
    .url('http://www.google.com')
    .title(function(err, res) {
        console.log('Title was: ' + res.value);
    })
    .end();

1 个答案:

答案 0 :(得分:2)

使用WebdriverIO有两种方法。独立模式允许您使用任意NodeJS脚本中的WebdriverIO API集成测试自动化(例如this example)。它通常用于将WebdriverIO嵌入到不同的库中,如Chimp.js

另一种方式是WDIO测试运行器(cli runner),它更适合于充分的e2e测试。它需要一个配置文件(wdio.conf.js或您想要的任何名称),并将此文件名作为参数传递给wdio cli命令(例如these examples)。如果您想为项目创建一个e2e测试套件,这是常用的方法。