I've been looking and doing research but the results are the same. Why does the it only run 2 times not to finish. When running the 3rd task cypress direct again to the login page.
describe("Overview Page", () => {
before("Behaviour to overview page", () => {
cy.SignIn();
cy.preverseAllCookiesOnce();
});
it("Overview Page Check (Sidebar and Header)", () => {
cy.intercept({
method: "GET",
url: "https://api.mapbox.com/**",
}).as("dataMapbox");
cy.intercept({
method: "GET",
url: "https://api.com/v2/**",
}).as("data");
cy.contains("Science Park").click();
cy.wait("@dataMapbox", { timeout: 90000 })
.its("response.statusCode")
.should("equal", 200);
cy.wait("@data", { timeout: 90000 })
.its("response.statusCode")
.should("equal", 200);
// sidebar
cy.get(".toc > .attached").as("sidebar");
cy.get("@sidebar").should("be.visible");
// page loaded
cy.wait(15000);
cy.get(".twelve > .header").should("have.text", "Overview");
});
it("Button Current and Dissmiss", () => {
// current and dismiss
cy.get(
':nth-child(1) > .top > [style="display: flex; align-items: center; flex-grow: 1; justify-content: flex-end;"] > .ui > .active'
).click();
});
it("Mapbox Button Check", () => {
cy.get(
':nth-child(2) > .top > [style="display: flex; align-items: center; flex-grow: 1; justify-content: flex-end;"] > .ui > .active'
).click();
for (let n = 0; n < 5; n++) {
cy.get('[data-tooltip="Map rotate 45 degree anticlockwise."]').click();
}
for (let n = 0; n < 5; n++) {
cy.get('[data-tooltip="Map rotate 45 degree clockwise."]').click();
}
});
});
The command.js
Cypress.Commands.add("preverseAllCookiesOnce", () => {
cy.getCookies().then((cookies) => {
const namesOfCookies = cookies.map((c) => c.name);
Cypress.Cookies.preserveOnce(...namesOfCookies);
});
});
Just found it out. This is the correct structure.
describe("Overview Page", () => {
before("Behaviour to overview page", () => {
cy.SignIn();
});
beforeEach("keep using the session", function () {
cy.preverseAllCookiesOnce();
});
})