Skip to content

Instantly share code, notes, and snippets.

@AlexZhukovich
Last active Sep 21, 2021
Embed
What would you like to do?
Testing redirect with Cypress

This gist shows how to create a Cypress test case that verifies redirect.

In the current example, the redirect-data.json has only one object. However, you can add more objects.

Article: https://alexzh.com/testing-redirect-with-cypress/

File pathes:

  • cypress/fixtures/redirect-data.json
  • cypress/integration/website-redirect/website-redirect.spec.js
[
{
"title": "TITLE OF THE ARTICLE",
"from": "OLD URL",
"to": "NEW URL"
}
]
import data from '../../fixtures/alexzh-com.json';
describe("website redirects", () => {
data.forEach(pageObj => {
it(`redirect of "${pageObj.title}" page`, () => {
cy.visit(pageObj.from, {failOnStatusCode: false});
cy.url()
.should("be.equals", pageObj.to)
cy.get("title")
.should("have.text", pageObj.title);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment