开发者

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开发者_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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜