【发布时间】:2021-10-15 07:10:05
【问题描述】:
我想扩展this question,因为我有一个类似的问题:
我想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')
即使元素确实存在并覆盖另一个元素并且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} 这是我从赛普拉斯得到的错误信息:
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>
{edit 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()
}
{edit 3}我对可能的解决方案进行的测试越多,我就越确信问题不在于覆盖,而在于赛普拉斯代码本身。
当我手动打开表单时,加载微调器消失的时间不会超过一秒,通常只需 0.1-0.2 秒。
然而,当 Cypress 打开表单时,表单无法正确加载,因为加载微调器会无限期地停留在那里。
【问题讨论】:
-
您能否提供一个完整的示例代码来重现您的问题?
-
完整的代码很长,并且使用了POM,但是我将代码的相关部分添加到了我的OP中
-
不幸的是,我不能给你一个应用程序本身的链接,因为它是私有的:(
-
我认为您可以使用
.invoke('show')更改元素的状态。这是一个简短的视频,解释了如何做到这一点。 testautomationu.applitools.com/advanced-cypress-tutorial/… -
谢谢。尝试了这个,虽然命令
cy.get('#lead_portlet').invoke('show')triggers 符合预期,但它并没有改变它被覆盖覆盖的事实:(
标签: javascript cypress wait assertion