问题描述
我正在寻找一个解决方案,在异步获取数据后定义Mocha测试。
现在,我使用或插件。
您是否直接在Mocha测试定义中了解另一种解决方案?
预先感谢,
用摩卡动态创建它()测试。
我终于像这样组织我的测试:
it('检查所有标签是否具有属性',function(){
var errors = [];
elements.forEach(function(element,index,array){
var $ = cheerio.load元素);
var tag = $(tagName); $ b $ if(tag.length){
if(!tag.attr(tagAttr))errors.push(element);
}
});
expect(错误).to.be.empty;
}
}
I'm looking for a solution to define Mocha tests after getting data asynchronously.
For now, I use gulp-webdriver to getting HTML content with Selenium. And I want tests certain HTML tags structure.
For example, I want to get all buttons structure from an HTML page.
1° In Mocha Before(), I get buttons :
var buttons = browser.url("url").getHTML("button");
2° And after that, I want tests each button in a separate it
:
buttons.forEach(function(button) { it() });
The only solution found is loading HTML and extract buttons with Gulp before launch Mocha test with data_driven or leche.withData plugin.
Do you know another solution directly in Mocha test definition?
Thanks in advance,
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测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!