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.
To use cy.session()
correctly you need to add another cy.visit()
after the session call.
That's because cy.session()
is caching.
That means the cy.visit()
inside it's setup
function is only called for the first test.
On the second test, you will get a blank page.
See Where to call cy.visit() for further details.
describe("Resource Add / Remove", () => {
beforeEach(() => {
cy.session(name, () => {
cy.visit('http://localhost/myapp') // only called on first test
const user = {
email: EMAIL,
password: PASSWORD,
};
cy.login(user);
cy.selectCustomer('MyCustomer')
})
cy.visit('http://localhost/myapp') // visit here when cache is active
})
it("should create a new resource", () => {
})
it("it should delete last created resource", () => {
})
})