我一直在为一个项目编写Cypress自动化测试,当我看到这些测试时,我注意到它们正在将一个页面呈现在另一个页面的顶部。您会在屏幕截图中看到,前一页在后台仍略显可见,所以当我试图找到一个元素时,它会发现前一页上的元素,因为它认为它“存在”,当它不在与我交互的页面上时。
因此,第一个图像是我正在测试的页面,它被正确地呈现。
一旦我点击“商人”的复选框,它会自动向下滚动页面,这是当它呈现上一页时,你会看到它用红色高亮显示。这种情况在手动测试时根本不会发生,只有在使用Cypress时才会发生。
我们已经建立了这个网络应用程序的反应使用梅。知道为什么会这样吗?这就像我向下滚动时呈现上一页一样(它使用相同的URL)。我试图更改Viewport设置,认为这可能是问题所在,但它并没有解决这个问题。
代码是非常基本的,是的。
it('User can add and remove a merchant', () => {
cy.get('[data-testid="New Email"]').click()
cy.get('#subject').type('Automation' + id)
cy.get('[role="textbox"]').type('This is dummy text for automation tests')
cy.get('[data-testid="attachments-upload"]').attachFile('pdftest.pdf')
// Check the Send Email is still disabled
cy.get('[data-testid="modal-button-Send Email"]').should('be.disabled')
// Add a merchant as a recipient by checking the checkbox
cy.get('[value="merchant"]').click()
cy.contains('button', 'Select Merchant').click() // Here is when the error happens
cy.contains('aaa@gmail.com').click()
cy.contains('button', 'Submit').click()
// Remove the merchant
cy.get('[data-testid="RemoveCircleIcon"]').eq(1).click()
})
发布于 2022-10-04 08:25:15
材料用户界面对每个动作都有动画。也许测试结束得太快了,你看到了画面中间的动画。
尝试添加最后一个断言,如
cy.contains('This is dummy text for automation tests')
.should('not.be.visible')
或
cy.contains('This is dummy text for automation tests')
.should('not.exist')
https://stackoverflow.com/questions/73939965
复制相似问题