【发布时间】:2017-09-11 12:16:27
【问题描述】:
在我的 testcafe 测试中,我有一个匹配多个节点的选择器。我想在此选择器匹配的 所有 节点上执行断言。
这将只对mySelector返回的第一个元素执行断言
await t.expect(mySelector.innerText).eql("foo");
这将在所有元素上执行它,但它真的很冗长:
const count= await mySelector.count;
for (let i = 0; i < count; ++i) {
await t.expect(mySelector.nth(i).innerText).eql("foo");
}
有没有我缺少的内置方法?
【问题讨论】:
-
.每个函数?
-
testcafe 在服务器端执行代码。没有jQuery
-
我不熟悉testcafe。我刚刚检查了type definition 的
Selector,它似乎不包括任何形式的children或childNodes。对于公开的内容,child函数(带有过滤器参数)可能会返回正确的选择器。 -
@ShanevandenBogaard:这就是为什么我使用
count和nth...child也无济于事。问题基本上出在except方法上,它只使用了选择器返回的第一项。 -
@Pytth:你是不熟悉。 testcafe 是一个 node.js 应用程序,即一个服务器应用程序。它不在浏览器上下文中执行
标签: javascript typescript testing automated-tests testcafe