Link Search Menu Expand Document

Cypress Command: followLink

Summary

cy.followLink($link) - Fetch the link specified by the `href` attribute on the given HTML `a` element and validate that the response has HTTP 200 status or behaves as annotated

Parameters

  • $link - The jQuery-wrapped link to click on, as provied by cy.get(). This will typically respresent an <a href="...">...</a> element.

Examples

cy.contains("the link text")
  .then($link => cy.followLink($link));
cy.get(...)
  .then($link => cy.followLink($link));

Waiting

This command will wait until the link is followed and its response is verified as specified by annotations.

Verification

This command will verify that href attribute of the $link responds with HTTP status 200, or as specified by annotations.

Instruction-Guided

This is an instruction-guided command: By using this command to ask Cypress to follow a link rather than calling cy.visit or cy.request, you will avoid having to remember to update your tests every time the URL changes.