Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining if a link exists w/ Cucumber/Capybara

I want to verify that a link with a specific href exists on a page. I am currently doing I should see "/some-link-here" but that seems to fail. How can I make sure that link exists without having to do click + I should be on "/some-link-here" page?

like image 900
Eric M. Avatar asked Nov 20 '25 20:11

Eric M.


1 Answers

You will need to add custom step

Then /^"([^\"]*)" should link to "([^\"]*)"(?: within "([^\"]*)")$/ do |link_text, 
page_name, container|
  with_scope(container) do
    URI.parse(page.find_link(link_text)['href']).path.should == path_to(page_name)
  end
end

You can use the step like Then "User Login" should link to "the user_login page", user_login is the name of your route

like image 115
jatin Avatar answered Nov 24 '25 07:11

jatin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!