Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test an image src and alt value using capybara?

I'm trying to write test the value of alt text + src of an image using capybara and the css selectors.

any idea s to test both in single xpath ?

like image 257
Shani Avatar asked Jun 25 '11 09:06

Shani


2 Answers

A slightly simpler way will be to use an id for that image:

page.find('#profile-avatar')['src'].should have_content 'default.png'

Updated for rspec 3:

expect(page.find('#profile-avatar')['src']).to have_content 'default.png' expect(page.find('#profile-avatar')['alt']).to match(/some-value/)

like image 84
Paul Ardeleanu Avatar answered Oct 03 '22 23:10

Paul Ardeleanu


variable=find(:xpath, "//img[@class='class_name']")
variable['src'].should == "url"
variable['alt'].should == "text"
like image 28
Srikanth Avatar answered Oct 03 '22 23:10

Srikanth