jeudi 14 janvier 2021

Why does a a Cypress test fail when rerunning after the first time

I am using Cypress to test an Angular application. I am using firefox as the browser option.

I have opened the Cypress GUI and Click on the test to start it. For example here I click on 'overview-ibc-list.spec.js'

enter image description here

The test runs successfully.

After that, I want to run the test again, so click the restart button. Or for example, I make changes in the code that are detected which restarts the test.

This time around though, the test fails because the original route I declared in cy.visit("http://localhost:4200/#/history/ibc/574015") is rerouted to the base URL ('http://localhost:4200/').

Shouldn't the test conditions not be the exact same the second time around?

My original thought is it could be some caching issue or local storage but I used the clearCookies and clearLocalStorage commands in the beforeEach function.

  beforeEach(() => {
    if (canRestart) {
      cy.reload(true);
      cy.clearCookies();
      cy.clearLocalStorage();
      cy.visit('http://localhost:4200/#/history/ibc/574015');
      canRestart = false;
    }
  });

So my question is why is this happening and how can I make the test environment the exact same when restarting the test from the first time around?

Currently, to successfully repeat the tests I have to navigate back to the menu in the GUI and stop the test completely, then click back on the test to restart it. Not Ideal

thanks.

Aucun commentaire:

Enregistrer un commentaire