We have this link which supposed to export a file. The link has an href which (somehow) is only applied in the UI if the download takes longer: The href basically shows the user that a file is being downloaded. Normally a user does not see it and also in the cypress launch app it is not visible in my test, nor does it open another tab.
Cypress, however, seems to always go to this href (I assume) (even if I remove href:
cy.contains(`a[href]`, 'Export')
.should('be.lengthOf', 1)
.invoke('removeAttr', 'href')
I can not get back normally to my page. It does not even recognize the first tag div[id=root], but in the launch app, it displays the expected page with the export button and a message box, for successful downloaded.
My only solution currently is, to save the url and revisit the saved url again after it clicks on the export button.
cy.url().then((url) => {
cy.contains(`a[href]`, 'Export')
.should('be.lengthOf', 1)
// .invoke('removeAttr', 'href') // does not make a difference!!!
.click({ force: true })
.then(() => {
// cy.get('div[id="root"]').should('be.lengthOf', 1);
cy.wait(1000); // wait for download
cy.visit(url);
});
});
But then I can not access the message box which appears after the download happend.
Is this really the only “crappy” solution in cypress? Selenium has no problem with this.
1