ruby on rails - How do I test an image alt value using capybara? -


I try to define a step to test the value of alt text of the image using Capybara and CSS selectors I am doing

I wrote one for input value based on readme examples:

  then / ^ me "([^ \"] *) "within" value Should look ([^ \ "] *)" Input $ / do Input_value, input_id | Element_value = Detect ("Input ## {input_id}"). Value element_value.should == input_value end  

but I can not understand this one ... something like this:

  then / ^ should see alttext " "([^ \"] *) "$ / Do | Alt_text | Element_value = location ("IMG") Value end  

Anyone know how I can find alt text value?

CAPABAR uses Xpath by default, unless you change that setting, Which can be part of your problem. (You can locate (CSS, "IMG [alt]") ).

I will write a test using xpath to see something like this:

  then / ^ alt text "([^ \"] *) "$ / "Value_xpath" ("// img [@alt"] within " = # {Alt_text} "Input $ / do | input_value, input_id | Page.should_xpath (" // input [@id = # {input_id} and text () = # {input_value}] end  

Comments