I've been searching for so long already but haven't found any solution.
I would like to check if a particular URL exists in the page. Rspec Capybara
for example: I'd like to check if the url http://project/guides/basics/ is in the page.
capybara has has_link
function but only accepts an id
or text
as a parameter so for this example,
<a href='http://project/guides/basics/'>
<div class='image-button-container'>
<img src='/images/basic_img.png'/>
</div>
</a>
how should I do the expect()
in Rspec using Capybara? Thanks
The following two should work:
expect(page).to have_link('', href: 'http://project/guides/basics/')
expect(page).to have_selector("a[href='http://project/guides/basics/']")
I was really hoping there is a better looking way, but unfortunately, I can't find one.
Capybara API provides method like below -
page.should have_link("Foo")
page.should have_link("Foo", :href=>"googl.com")
page.should have_no_link("Foo", :href=>"google.com")
For your specific sample you can find all elements and then check if a
is there with specific div and image. like below -
page.all("a[href='http://project/guides/basics/'] div img")[0]['src'].should be('/images/basic_img.png')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With