我想进一步讨论这个问题,因为我有一个类似的问题:
我想要
即使元素存在且覆盖其他元素,Cypress 也会通过断言,而
是否有任何方法来解决这个问题?
我想要
cy.get('#lead_name').type('foo')
,但在表单加载时,它被一个不透明度为0.9的元素覆盖。<div class="blockUI blockOverlay" style="z-index: 1000; border: none; margin: 0px; padding: 0px; width: 665px; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); opacity: 0.9; cursor: wait; position: absolute;"></div>
当我开始使用断言时
cy.get('#lead_name').should('be.visible)
虽然断言通过了(可能是因为不透明度?),但当我尝试在字段中输入时,却收到元素被覆盖的错误消息。
当我尝试断言覆盖层不再存在并添加以下内容时
cy.get('.blockUI blockOverlay').should('not.exist')
即使元素存在且覆盖其他元素,Cypress 也会通过断言,而
cy.get('#lead_name').type('foo')
失败。是否有任何方法来解决这个问题?
//This does not work it's just a sample to explain what I want to do
//test if the element I want to get is not covered
cy.get('#lead_name').should('not.be.covered')
//or test if the element is actionable
cy.get('#lead_name').should('be.actionable')
如何确保它等待表单加载完毕?
{edit} 这是我从Cypress得到的错误信息:
Timed out retrying after 4000ms: cy.type() failed because this element:
<input name="CrmLead[first_name]" id="CrmLead_first_name" type="text" maxlength="255">
is being covered by another element:
<div class="blockUI blockOverlay" style="z-index: 1000; border: none; margin: 0px; padding: 0px; width: 665px; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); opacity: 0.9; cursor: wait; position: absolute;"></div>
{编辑 2} 这是我使用的代码,仅包含相关部分:
it('should select new lead', () {
cy.visit(Cypress.env('lead_url'))
cy.get('#new_lead).click() //this opens the new form which takes some time to load
cy.get('#lead_name').type('foo')
cy.get('#lead_last_name').type('bar')
cy.get('.button').click()
}
{编辑3}我测试了很多可能的解决方案后,越来越确信问题不在叠加层上,而是Cypress代码本身存在问题。
当我手动打开表单时,加载旋转图标消失的时间从未超过一秒钟,通常只需0.1-0.2秒钟。
然而,当Cypress打开表单时,表单无法正常加载,因为加载旋转图标一直停留在那里。
.invoke('show')
来改变元素的状态。这里有一个简短的视频,解释了如何做到这一点。https://testautomationu.applitools.com/advanced-cypress-tutorial/chapter4.html - ItsNotAndycy.get('#lead_portlet').invoke('show')
,虽然它按预期触发了,但它并没有改变被覆盖的Overlay的事实 :( - cypher_null