I have the following test, written in Cypress. I use VueJS with SSR support for my frontend. My app it’s an SPA and I am testing the user click on a menu.
before(() => {
// mock data etc.
});
it('should check if component render properly without ssr', () => {
cy.visit('url');
cy.wait(1000);
cy.get('.menuElement').click();
cy.get('.something').should($something => {
expect($something).to.have.length(10);
});
});
According to Cypress’ best practices, I shouldn't use cy.wait in this form. But the problem is; without the wait, the test will fail. I tried using:
{ timeout: 10000 }as param in cy.get and cy.visit- aded something like
.should('be.visible');(for waiting when will be visible) - added route with
cy.wait("@abc")
But none of the above works for me.
Please suggest a solution. What should I do that everything works correctly in my case?
Apart from showing the code with cy.wait(), you didn't show the code that is not working. What is the defaultTimeout you have configured in
cypress.jsonfile. And how long is your page taking to load...Cypress by default takes 4 secs for any cypress command and it gets timeout if element doesn't exist on DOM or page is not loaded. So you can increase
pageLoadTimeoutso that cypress will wait for page to fully load till 10 secs, if page is loaded within 2 secs, then immediately it will executecy.get()commandNote: I used to use lot of cy.wait() and after I started using the timeouts effectively, there was no issue for me. Please read cypress configuration documentation