我正在寻找一种在异步获取数据后定义 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 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!