我正在寻找一种在异步获取数据后定义 Mocha 测试的解决方案.
I'm looking for a solution to define Mocha tests after getting data asynchronously.
目前,我使用 gulp-webdriver 通过 Selenium 获取 HTML 内容.我想测试某些 HTML 标签结构.
For now, I use gulp-webdriver to getting HTML content with Selenium. And I want tests certain HTML tags structure.
例如,我想从 HTML 页面中获取所有按钮结构.
For example, I want to get all buttons structure from an HTML page.
1° 在 Mocha Before() 中,我得到按钮:
1° In Mocha Before(), I get buttons :
var buttons = browser.url("url").getHTML("button");
2° 然后,我想在单独的 it 中测试每个按钮:
2° And after that, I want tests each button in a separate it :
buttons.forEach(function(button) { it() });
找到的唯一解决方案是在使用 data_driven 启动 Mocha 测试之前使用 Gulp 加载 HTML 和提取按钮或 leche.withData 插件.
The only solution found is loading HTML and extract buttons with Gulp before launch Mocha test with data_driven or leche.withData plugin.
您知道直接在 Mocha 测试定义中的另一种解决方案吗?
Do you know another solution directly in Mocha test definition?
提前致谢,
似乎不可能用 mocha 动态创建 it() 测试.
It doesn't seem possible to dynamically create it() tests with mocha.
我终于像这样组织我的测试了:
I finally organise my test like this :
it('Check if all tag have attribute', function() {
var errors = [];
elements.forEach(function(element, index, array) {
var $ = cheerio.load(element);
var tag = $(tagName);
if (tag.length) {
if (!tag.attr(tagAttr)) errors.push(element);
}
});
expect(errors).to.be.empty;
}
}
这篇关于从 webdriver.io 获取数据后动态构建 Mocha 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Browserify,Babel 6,Gulp - 传播运算符上的意外令牌Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 传播运算符上的意外令牌)
是否可以将标志传递给 Gulp 以使其以不同的方式Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以将标志传递给 Gulp 以使其以不同的方式运行任务
为什么我们需要在全局和本地安装 gulp?Why do we need to install gulp globally and locally?(为什么我们需要在全局和本地安装 gulp?)
如何一个接一个地依次运行 Gulp 任务How to run Gulp tasks sequentially one after the other(如何一个接一个地依次运行 Gulp 任务)
由于 MIME 类型而未加载样式表Stylesheet not loaded because of MIME-type(由于 MIME 类型而未加载样式表)
打开 Javascript 文件时 Visual Studio 2015 崩溃Visual Studio 2015 crashes when opening Javascript files(打开 Javascript 文件时 Visual Studio 2015 崩溃)