Build Mocha test dynamically after getting data from webdriver.io(从 webdriver.io 获取数据后动态构建 Mocha 测试)
问题描述
我正在寻找一种在异步获取数据后定义 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 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 webdriver.io 获取数据后动态构建 Mocha 测试


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01