Why navigation testing validates routing in Cypress - Automation Benefits in Action
describe('Navigation Routing Test', () => { beforeEach(() => { cy.visit('/'); }); it('should navigate to About page and verify URL and content', () => { cy.get('nav').contains('About').click(); cy.url().should('include', '/about'); cy.get('main').should('contain.text', 'About Us'); }); it('should navigate to Contact page and verify URL and content', () => { cy.get('nav').contains('Contact').click(); cy.url().should('include', '/contact'); cy.get('main').should('contain.text', 'Contact Information'); }); });
This test suite uses Cypress to automate navigation testing.
beforeEach ensures each test starts on the home page.
Each test clicks a navigation link by finding it inside the <nav> element using cy.get('nav').contains('LinkText'). This simulates a user clicking the link.
Then cy.url().should('include', '/expected-path') verifies the URL changed correctly, confirming routing works.
Finally, cy.get('main').should('contain.text', 'Expected Content') checks the page content updated to the correct page, ensuring the navigation loaded the right content.
We avoid hardcoded waits because Cypress automatically waits for elements and URL changes, making tests reliable and fast.
Now add data-driven testing with 3 different navigation links and their expected URLs and page contents