如果一个元素在页面上不可操作(在这种情况下,由另一个元素覆盖)并且您尝试单击它,赛普拉斯将显示如下错误:
CypressError: Timed out retrying: cy.click() failed because this element:
<span>...</span>
is being covered by another element:
Run Code Online (Sandbox Code Playgroud)
大!但有没有办法断言这是这种情况,又称无法点击该元素?
这不起作用:
should.not.exist - 元素确实存在should.be.disabled - 该元素未被禁用should.not.be.visible - 元素可见(刚被另一个透明元素覆盖)cy.on('uncaught:exception', ...),因为这不是一个例外我有关于赛普拉斯的问题。
我在页面上有一个并不总是出现的元素。什么时候显示,什么时候不显示是没有逻辑的。
在赛普拉斯中是否有一些 IF/THEN 函数或其他什么东西,你如何检查元素是否显示(所以填写它),当你没有看到它时跳过那一步?
我的代码:
if (Cypress.$('[data-bind="validationElement: interestInsurable"]').length > 0) {
cy.get('[for="p4-conditional-csob-interest-insurable-1"]').click()
}
else {cy.get('#car-info-serie')}
Run Code Online (Sandbox Code Playgroud)
这是操场上的样子: 图片
还有那个复选框的HTML:
<label class="z-radio z-radio-inline primary" for="p4-conditional-csob-interest-insurable-1" data-bind="popover: { content: VehicleInsuranceTooltips.conditionalDataCsobInterestInsurable1Tooltip }" data-original-title="" title="">
<input id="p4-conditional-csob-interest-insurable-1" name="p4-conditional-csob-interest-insurable" type="radio" class="custom-radio" data-toggle="radio" data-bind="checkedValue: 1, checked: interestInsurable" value="1">
<span class="icons">
<span class="icon-unchecked"></span>
<span class="icon-checked"></span>
</span>
Pat?í vozidlo zájemci o pojišt?ní?
</label>
Run Code Online (Sandbox Code Playgroud) 我阅读了有关赛普拉斯条件测试的文档中的警告,但由于某些原因仍然需要将其应用于特定测试。
我有一个函数可以做到这一点,但由于该函数中缺乏重试,某些选择器无法工作。
如何在条件测试中实现重试并避免不稳定的测试?
这是否有可能,或者一件事可以抵消另一件事吗?
export function elementExists(selector: string): boolean {
try {
return Cypress.$(selector).length > 0;
} catch (error) {
return false;
}
Run Code Online (Sandbox Code Playgroud)