Posted about 1 month 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.exact = prior_match_strategy end

Use it with

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

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Tobias Kraze
Last edit:
6 days ago
by Judith Roth
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 cookies to improve usability and analyze traffic.
Accept or learn more