Reputation: 15935
In cypress
I am trying to create a random number, in one spec, posting it to the first website
Navigate to another website with different origin, want to assert that this random number generated in the first test, is available on the second website since they are linked in the backend
This won't happen as same code to create random number would run again, in case we generate in before() block, thus creating and assigning another random number to that variable, since before() block will run again in case we visit another url
few ways like using -
None of them worked, although if we were not to visit another url, all of them would work normally
Upvotes: 0
Views: 2086
Reputation: 15935
This is documented here https://github.com/cypress-io/cypress/issues/2636 that it is not possible to use cy.visit to visit different origin websites and maintain state
I have two solutions for such scenarios
cy.writeFile
to write in the first run, and cy.readFile
to read in next run, since it actually writes to file system, this gets persisted and thus solves our problem, we are able to maintain stateUpvotes: 1