So, i have setup 2 customCommands for my Cypress setup setupProject
and removeProject
. Both click through the UI to create a Project, and to delete a Project. It also work as I expect it to. However the removeProject
does only work, if no fail occurs in the tests.
If a fail happens, Cypress will not wait for timeouts or does not do clicks in the after hook. Therefore i have to do cy.wait(4000)
and .click({force: true})
// test.cy.ts
before(() => cy.setupProject(PROJECT_NAME))
after(() => cy.removeProject(PROJECT_NAME))
// commands.ts (does work with no failure, but not with failure)
Cypress.Commands.add('removeProject', (projectName: string) => {
PROJECT_SELECTION_PAGE.visit()
PROJECT_SELECTION_PAGE.getProjectDropdown().click()
PROJECT_SELECTION_PAGE.getProjectOption(projectName).first().click()
PROJECT_OVERVIEW_PAGE.DELETE.getButton().click()
PROJECT_OVERVIEW_PAGE.DELETE.dialogIsVisible()
PROJECT_OVERVIEW_PAGE.DELETE.getConfirmButton().click()
})
// commands.ts (does with failure and without)
Cypress.Commands.add('removeProject', (projectName: string) => {
PROJECT_SELECTION_PAGE.visit()
cy.wait(4000)
PROJECT_SELECTION_PAGE.getProjectDropdown().click({ force: true })
cy.wait(4000)
PROJECT_SELECTION_PAGE.getProjectOption(projectName).first().click({ force: true })
cy.wait(4000)
PROJECT_OVERVIEW_PAGE.DELETE.getButton().click({ force: true })
cy.wait(4000)
PROJECT_OVERVIEW_PAGE.DELETE.dialogIsVisible()
cy.wait(4000)
PROJECT_OVERVIEW_PAGE.DELETE.getConfirmButton().click({ force: true })
})
What am I doing wrong with this? If I put the logic in a seperate it('remove project')
it does work. But that would mean, I have to copy&paste this logic into every test...