gpt4 book ai didi

javascript - 从 webdriver.io 获取数据后动态构建 Mocha 测试

转载 作者:搜寻专家 更新时间:2023-11-01 05:29:52 27 4
gpt4 key购买 nike

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

现在,我使用 gulp-webdriver使用 Selenium 获取 HTML 内容。我想测试某些 HTML 标签结构。

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

1° 在 Mocha Before() 中,我得到按钮:

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

2° 之后,我想在单独的 it 中测试每个按钮:

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

找到的唯一解决方案是在使用 data_driven 启动 Mocha 测试之前使用 Gulp 加载 HTML 和提取按钮或 leche.withData插入。

您知道直接在 Mocha 测试定义中的另一种解决方案吗?

提前致谢

最佳答案

用 mocha 动态创建 it() 测试似乎是不可能的。

我终于这样组织了我的测试:

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;
}
}

关于javascript - 从 webdriver.io 获取数据后动态构建 Mocha 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34001054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com