如果柏树中不存在元素,如何跳过测试
我正在编写一个测试,如果我降落在页面上,并且如果有任何记录,我需要单击记录附近的三个点按钮。但是,如果页面上没有记录,我应该跳过测试。
cy.get('body')
.then(($body) => {
if ($body.find('.ant-empty-description').length) {
cy.log('Element not found. Skip the Test')
}
else {
cy.xpath("//tbody[@class='ant-table-tbody']//tr[" + rowNumber + "]//td[4]//button//em").click()
}
})
我正在使用一种方法,如果存在“未找到的记录”消息,我需要跳过测试,请单击记录附近的按钮。
I am writing a test in which if I land on a page and if any records are available, I need to click on three dots buttons near the record. But I should skip the test if no records are available on the page.
cy.get('body')
.then(($body) => {
if ($body.find('.ant-empty-description').length) {
cy.log('Element not found. Skip the Test')
}
else {
cy.xpath("//tbody[@class='ant-table-tbody']//tr[" + rowNumber + "]//td[4]//button//em").click()
}
})
I am using an approach in which if 'No Record found' message is present, I need to skip the test else click on the button present near the record.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有时需要进行有条件测试,但是使用
< body>
作为基本元素是错误的IMO。< body>
始终在页面上,但是表数据可能不会从API中获取。测试的运行始终比API更快,总是会看到空排占位符。
使用的模式
添加
intercept()
并等待API响应。使用表行作为条件检查的基本元素 - 总会至少有一行(但可能是“无记录”行)。
Sometimes it's necessary to test conditionally, but using
<body>
as a base element is a mistake IMO.<body>
is always on the page, but the table data may not be if fetched from an API.The test will always run faster than the API, always see the empty row placeholder.
Pattern to use
Add an
intercept()
and wait for the API to respond.Use the table rows as base element for conditional check - there will always be at least one row (but it may be the "No records" row).
您可以使用 Mocha's
.skip()
功能。请注意,您必须使用函数()
而不是箭头功能。话虽这么说,我同意@jjhelguero的观点 - 以这种方式使用跳过是用于测试的反图案。理想情况下,您应该控制一个元素是否会出现在网页上,并使用测试设置将页面操纵到具有/没有元素的情况下。
You can use mocha's
.skip()
functionality. Please note that you'll have to usefunction()
instead of arrow functions.That being said, I agree with @jjhelguero -- using skips in this way is an anti-pattern for testing. Ideally, you should control whether or not an element will appear on the webpage, and use your test setup to manipulate the page into having/not having the element.