Posted over 2 years ago. Visible to the public.

Handling duplicate links with Capybara and Cucumber

Sometimes, you might have duplicate links on a page. Trying to click those links will by default cause Capybara to raise an Ambiguous match error.

If you do not care about which of those links are clicked, you can disable this errors by adding the following meta step:

Copy
When(/^(.*) \[allow ambiguous\]$/)do |step_text| prior_match_strategy = Capybara.match Capybara.match = :first step(step_text) ensure Capybara.match = prior_match_strategy end

Use it with

Copy
When I follow "a duplicate link" [allow ambiguous]

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Avatar
Tobias Kraze
Last edit:
over 1 year ago
by Henning Koch
Keywords:
match, prefer, exact
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Tobias Kraze to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more