I am testing adding and removing resource in my app. Currently it clears the cookies and does login and customer selection before each test case. My app checks if the cookies are gone then it redirects you back to login page.
describe("Resource Add / Remove", () => {
let resourceName;
beforeEach(() => {
cy.visit('http://localhost/myapp')
const user = {
email: EMAIL,
password: PASSWORD,
};
cy.login(user);
cy.selectCustomer('MyCustomer')
});
it("should create a new resource", () => {
resourceName = "MyResource";
// create new resource and check if it exist
});
it("it should delete last created resource", () => {
// find resource using resourceName in the list and click on delete button
// check if it is removed from the list
});
});
But this is really time consuming… After creating a new resource I just want to jump to next test case and skip login and customer selection from the beginning.
How to do this?
In Cypress preserveOnce
is now removed.
2
Answers
cy.session()
should accomplish your goal of caching cookies. From the documentation:In your case, it could look something like the following:
However, Cypress recommends using
cy.session()
inside a custom login command.If all you want to do is preserve a cookie, I recommend cypress-v10-preserve-cookie.
It has a very simple usage, just use it the same as the old
preserveOnce()
.