Skip to content

Instantly share code, notes, and snippets.

@AlexZhukovich
Last active September 21, 2021 07:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AlexZhukovich/8706d574562d0595797e2ad8451a4cfd to your computer and use it in GitHub Desktop.
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