在我的cypress项目中有一个命令,该命令应该从用户的帐户中删除某个实体(文件)的所有注册表,并在每次测试之前运行。
主要步骤如下:
// Await loading
cy.contains('Carregando...').should('not.be.visible')
// Find all delete buttons by its svg path
cy.get(
`[d='M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z']`,
)
.parent()
.parent()
.parent()
.each((delete_button, index, list) => {
cy.wrap(delete_button).click({ force: true })
// Fills in modal using the correct deletion phrase.
cy.contains(/^Escreva "(.*)" para confirmar/).then(el => {
const reg = RegExp(/^Escreva "(.*)" para confirmar/)
const confirmation = reg.exec(el[0].innerText)[1]
cy.get(`[placeholder='${confirmation}']`).type(`${confirmation}{enter}`)
})
cy.contains('Carregando...', { timeout: 60000 }).should('not.be.visible')
})
// Asserts that table section is all clear
cy.get('span').should(
'contains.text',
'Ao inserir uma tabela no sistema você poderá criar fluxos e treinar seus modelos a partir da sua base de dados.',
)
在第一次测试中,由于项目中包含一些条目,因此此命令可以正常通过,但是在接下来的测试中,它将失败,因为get命令找不到任何svg作为在屏幕上查找按钮的参考。
如何更改此命令,以便在出现以下两种情况时都可以通过:
答案 0 :(得分:0)
您似乎需要首先检查element existence?
cy.get('body').then(($body) => {
if ($body.find('[d=...]').length) {
// svg was found, find the buttons
cy.get('[d=...]')
...the rest of your code...
}
}