describe("Handle tab-approach1", () => {
it("Approach1", () => {
cy.visit("https://the-internet.herokuapp.com/windows"); // parent tab;
cy.get(".example > a").invoke("removeAttr", "target").click(); // clicking link;
cy.url().should(
"include",
"https://the-internet.herokuapp.com/windows/new"
);
cy.wait(5000);
// operations
cy.go("back"); // back to parent tab
});
});
it("Approach2", () => {
cy.visit("https://the-internet.herokuapp.com/windows"); // parent tab;
cy.get(".example > a").then((e) => {
let url = e.prop("href");
cy.visit(url);
});
cy.url().should(
"include",
"https://the-internet.herokuapp.com/windows/new"
// if the domain is totally different from the parent one then it's not working
);
cy.wait(5000);
// operations
cy.go("back"); // back to parent tab
});
Sources
https://docs.cypress.io/api/commands/invoke#Use-invoke-to-test-HTML-content
invoke | Cypress Documentation
Invoke a function on the previously yielded subject.
docs.cypress.io