Capybara Ambiguity Resolution

前端 未结 9 1309
轮回少年
轮回少年 2020-12-23 13:59

How do I resolve ambiguity in Capybara? For some reason I need links with the same values in a page but I can\'t create a test since I get the error

Failure/         


        
9条回答
  •  不思量自难忘°
    2020-12-23 14:46

    As considering all the above options, you can try this too

    find("a", text: text, match: :prefer_exact).click
    

    If you are using cucumber, you can follow this too

    You can pass the text as a parameter from the scenario steps which can be generic step to reuse again

    Something like When a user clicks on "text" link

    And in step definition When(/^(?:user) clicks on "([^"]*)" (?:link)$/) do |text|

    This way, you can reuse the same step by minimizing the lines of code and would be easy to write new cucumber scenarios

提交回复
热议问题