When I follow "link"

This step follows a link by the text a person reads on it. It looks for a link whose accessible name is exactly that text (Playwright's getByRole('link', { name, exact: true })), and for an <a> element whose whole text is that text. White space around the text and inside it, the way a template prints it, does not count. Unlike I click, it only follows links: it never presses a button that happens to carry the same label.

It follows the first matching link a person can see. A site that keeps a hidden copy of its links in a closed dropdown or a mobile menu puts that copy first in the page, and the step passes over it. It waits up to 5 seconds for a visible match. When the page has links of that name but none of them is visible, it says so, for example the page has 2 links named "About", but none is visible (a closed menu, a hidden section). When there is no link of that name at all, it fails with the text it looked for and the same hints as the other text steps. The match is case-sensitive: "Read more" does not match a link that reads "Read More".

Accepted phrasings

When I follow "Contact Us"
When we follow "Home"
And follow "Read more"

Examples

When I follow "Contact Us"
When I follow "About"
When we follow "Home"
And follow "Read more"
When I follow "Documentation"
When we follow "Sign in"
When I follow "Log out"
When I follow "Download report"
And I follow "Previous"
When I follow "Next"

In a real scenario

Scenario: Open the about page from the main menu
  Given I am on "/"
  When I follow "About"
  Then I should be on "/about-us"
    And I should see "Our story"

Follow or click?

  • I follow when the scenario means "go to that page through its link".
  • I click for anything a person clicks, a button as well as a link.
  • A link with no readable text, such as an icon: click it by an attribute.

Related steps

Back to Action Steps