我有以下规格:
context('Contact update', () => {
it.only('Can update contact', () => {
const address = 'new address 123'
const cardId = 'c2card-38AF429999C93B5DC844D86381734E62'
cy.viewport('macbook-15')
cy.authVisit('/contact/list')
cy.getByTestId('open-doc-Aaron Dolney-0').click()
cy.get('[name="physicaladdress"').type(`{selectall}{backspace}${address}`)
cy.getByTestId(cardId, 'save-button').click()
cy.getByTestId(cardId, 'loading')
cy.get('[name="physicaladdress"').should('have.value', address)
})
})
getByTestId
是我为了减少一些样板文件而编写的命令:
Cypress.Commands.add('getByTestId', (...ids) => {
const id = ids.map(id => `[data-testid="${id}"]`).join(' ')
return cy.get(id)
})
当我用除此之外的任何东西运行它时cypress open
,它无法获取加载指示器。我认为我的测试端点响应太快并且切换加载指示器太快。
是否有更好、更一致的方法来验证加载指示器的显示?
我也在努力解决这个问题,因为我想确保加载指示器显示,所以我必须变得有点狡猾。我找到cy.route()
has an onRequest
选项,而这正是我所需要的。
https://docs.cypress.io/api/commands/route.html#Options https://docs.cypress.io/api/commands/route.html#Options
cy.server();
// Verify that the loading indicator is shown before the request finishes
cy.route({
url: url_of_request_that_triggers_loading,
onRequest: () => {
cy.getByTestId(cardId, 'loading');
},
});
通过此实现,我们在请求完成之前和加载指示器消失之前运行加载期望。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)