问题描述
我是 webdriverio 的新手.我不明白它应该如何在节点应用程序中配置和使用.导入 webdriverio 时如何运行规范"测试?可以吗?
I'm new to webdriverio. I don't understand how it's supposed to be configured and used within a node application.How do you run 'spec' tests when webdriverio is being imported? Can it be done?
// 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();
推荐答案
有两种使用 WebdriverIO 的方法.独立模式允许您在任意 NodeJS 脚本中使用 WebdriverIO API 集成测试自动化(例如 这个例子).它通常用于将 WebdriverIO 嵌入到不同的库中,例如 Chimp.js.
There are two ways to use WebdriverIO. The standalone mode allows you to integrate test automation using the WebdriverIO API within arbitrary NodeJS scripts (e.g. this example). It is often used to embed WebdriverIO into a different library like Chimp.js.
另一种方式是 WDIO 测试运行器(cli runner),它更适合足够的 e2e 测试.它需要一个配置文件(wdio.conf.js 或您想要的任何名称)并将此文件名作为参数传递给 wdio cli 命令(例如 这些示例).如果您想为项目创建 e2e 测试套件,这是常用的方法.
The other way is the WDIO test runner (cli runner) which is better suited for sufficient e2e testing. It requires a configuration file (wdio.conf.js or whatever name you want) and to pass this file name as argument to the wdio cli command (e.g. these examples). This is the common way if you want to create an e2e test suite for your project.
这篇关于将 WebdriverIO 'spec' 测试作为节点文件运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!