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开发者_JAVA百科 should see the image "(.+)"$/ do |image|
page.should have_xpath("//img[@src=\"/public/images/#{image}\"]")
end
Try page.should have_xpath("//img[contains(@src, \"#{image}\")]")
, which will match any img
whose src
contains your filename.
If you have the option then using a css selector is more concise in this case:
page.should have_selector( :css, "a[href$='#{image}']")
Note the '$
' on then end of 'href$
' to denote matching against the end of the string.
精彩评论