datatables - 柏树 | 检查搜索关键字是否与显示的 trs 的任何 td 的值匹配
问题描述
我正在测试一种搜索功能,该功能根据用户的名字、姓氏、角色或电子邮件过滤输入的字符。
我有一个table
with multiple tr
,每个tr
都有多个td
.
我想断言返回的行包含td
与输入的关键字匹配的任何值。
我创建了以下帮助函数,但cy.get('td').contains(searchKeyword);
导致浏览器挂断。任何想法可能是这里的解决方案。
assertCorrectFilterResults(searchKeyword: string) {
this.elements.tableBody().find("tr").then(rows => {
rows.toArray().forEach(row => {
cy.get('td').contains(searchKeyword);
})
});
};
我的助手受到此处提到的解决方案的启发How to get the total number of Rows in a table | 柏
解决方案
如果您直接想查看td
元素,则可以直接遍历它们。
为了与searchKeyword
cy.get('tbody.MuiTableBody-root tr td').each(($ele) => {
if($ele.text().trim() == searchKeyword){
expect($ele.text().trim()).to.equal(searchKeyword) //Assertion for exact text
}
})
对于部分匹配searchKeyword
cy.get('tbody.MuiTableBody-root tr td').each(($ele) => {
if($ele.text().trim().includes(searchKeyword)){
expect($ele.text().trim()).to.include(searchKeyword) //Assertion for partial text
}
})
推荐阅读
- php - 测试依赖项和测试 get 和 setter 在一起
- xamarin - 从后面的代码中为按钮设置 HelpText 在 Xamarin.Forms 中不起作用
- python-3.x - 写出netcdf文件时如何阻止xarray自动更改时间属性?
- postgresql - Postgres 更新 jsonb 字段
- r - 根据 R 中的单元格值构建数据框的子集列表
- git - 使用 git clone 时如何修复“找不到您要查找的项目”
- angular - 错误:formGroup 需要一个 FormGroup 实例。请传入一个
- java - 如何在不更改 Spring Boot 中的实际类的情况下远程创建 bean?
- python - 我如何使用 python 从 json 输出中获取一个单词
- ansible - 合并主机所属组中的所有变量