从webdriver.io获取数据后动态构建Mocha测试 [英] Build Mocha test dynamically after getting data from webdriver.io

查看:130
本文介绍了从webdriver.io获取数据后动态构建Mocha测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个解决方案,在异步获取数据后定义Mocha测试。



现在,我使用 gulp-webdriver

使用Selenium获取HTML内容。
我想测试某些HTML标签结构。



例如,我想从HTML页面获取所有按钮结构。

1°在摩卡Before(),我得到按钮:

  var buttons = browser.url(url)。getHTML(button); 



<2>然后,我想要测试每个按钮在一个单独的

  buttons.forEach(function(button){it()}); 

唯一的解决方法是在启动Mocha测试之前加载HTML并提取Gulp按钮, data_driven leche.withData 插件。

您是否直接在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测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆