I want to test if I have 0, 1, 2 or 3 times a picture ('foo.png')
Thanks
"text">
Write a custom cucumber step Will be a custom RSPC that uses the predecessor.
The pseudo code will look something like this.
Features / page feature
I'm on the pages of images, then I should see 3 images attributes / step_definitions / Page_steps.rb
This file will use Nokogiri to collect all the images with any name and then use RSPC to validate your expectations.
then / ^ I should look. (). $ Images $ / do | Num_of_images | Html = Nokogiri :: HTML (response.body) tag = html.xpath ('// img [@src = "/ public / images / foo.png"]') tags. The length.should eql (num_of_images) end Here is a Rapic example working which shows how to use Nokhokri .pp
The description of "nogogiri" is to be "imagecount", "should be 4 image" html = nokogiri :: html (' gt; body & gt; & lt; div id = "" & Gt; & lt; img src = "/ public / images / foo.png" & gt; & gt; / div & gt; & lt; div id = "" & gt; & lt; img src = "/ public / Images / foo.png "& gt; & lt; / div & gt; & lt; div id =" "& gt; & lt; img src =" / public / images / foo.png "& gt; div / Gt; & lt; div id = "" & gt; & lt; img src = "/ public / images / foo.png" & gt; ; & Lt; / div & gt; & lt; / html> gt; & lt; / body & gt; ') tag = html.xpath (' // img [@src = "/ public / images / foo.png "] ') Tags.length.should eql (4) Finally" should be 3 image "html = nokogiri :: HTML (' gt; body gt; & lt; / body & gt; ') tag = html.xpath (' // img [@src = "/ public / images / foo .png "] 'tag. Length.should eql (3) Finish it should be" 1 image "html = Nokogiri :: HTML (' & lt; html & gt; & lt; body & gt; & lt; div Id = "" & gt; & lt; IMG src = "/ public / images / bar.png" & gt; & lt; / html & g T; & lt; / body & gt; ') tag = html.xpath (' // img [@src = "/ public / images / foo.png"] ') tags.length.should eql (1) End End
Comments
Post a Comment