Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do an xpath regex search in my Cucumber / Capybara step definition (Rails 3)?

I have a Scenario that validates that the image I just uploaded exists on the next page.

This below works great, except that I have a variable folder structure based on the listing_id. How can I use regex here to match image to only the filename instead of the entire url?

Then /^I should see the image "(.+)"$/ do |image|
    page.should have_xpath("//img[@src=\"/public/images/#{image}\"]")
end
like image 941
Jamis Charles Avatar asked Jan 27 '11 18:01

Jamis Charles


1 Answers

Try page.should have_xpath("//img[contains(@src, \"#{image}\")]"), which will match any img whose src contains your filename.

like image 108
Dylan Markow Avatar answered Nov 13 '22 09:11

Dylan Markow