cypress .each().wrap()。
我正在尝试检查表中显示的项目是否有一些断言。我的方式是将所有项目都放在数组中,然后在该数组上迭代。
我的问题:所有断言已经通过,但是柏树跑者仍然需要大量时间来完成CY.Wrap(.invoke(text))作业。
由于这是我的柏树测试的非常核心的命令,具有更有效的功能将很棒。
我的命令:
cy.get('table tbody').within(() => {
cy.get('tr').each((tr) => {
cy.wrap(tr.children().eq(index)).invoke('text').then((text) => {
text = text.trim();
arrayWithValuesOfTheList.push(text);
});
})
.then(() => {
//in here all the (quickly passing) assertions are...
});
});
感谢提前的任何帮助。感谢大家!
I am trying to check the items shown in my table for some assertions. My way is to put all of the items in an array and then iterate over that array.
My problem: All assertions already passed but the cypress runner still takes a lot of time to finish the cy.wrap(.invoke(text)) jobs.
Since this is a very core command of my cypress tests it would be great to have a more efficient function.
My command:
cy.get('table tbody').within(() => {
cy.get('tr').each((tr) => {
cy.wrap(tr.children().eq(index)).invoke('text').then((text) => {
text = text.trim();
arrayWithValuesOfTheList.push(text);
});
})
.then(() => {
//in here all the (quickly passing) assertions are...
});
});
Thanks for any help in advance. I appreciate you all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以避免包裹该值,会提高速度,但很难说最慢的部分。
You can avoid wrapping the value, will give some increase in speed but it's hard to say what is the slowest part.
如果您想在单个单元格上断言,请使用
.east($ cell => {...})
很好,但是如果您需要全柱断言(例如.east()
排序,唯一值)变得困难。要构建适合各种测试的东西,请查看此处的模式。 nofollow noreferrer“>对表进行排序。
这个想法是使用
.map()
为选定的表行和列创建助手功能。If you want to assert on individual cells, using
.each($cell => {...})
is fine but if you want whole-column assertions (e.g sorted, unique-values) it gets difficult with.each()
.To build something adaptable for various tests, take a look at the pattern here Sorting the table.
The idea is to create helper functions using
.map()
to selected table rows and columns.Addressing performance issue
If performance is poor, you can reduce the number of process steps at the Cypress command level by using jQuery-only commands.
This will avoid adding commands to the Cypress queue which is likely to be the slowest part
您可以做这样的事情。它获取
tr
一个值一个值,并与正则匹配的模式匹配。You can do something like this. It gets the
tr
values one by one and matches in against a regex pattern.