I have a webpage that I display in a printer friendly format with headlines followed by items belonging to that group. Example:
Headline1
=========
Item1
Item2
Item3
Headline2
=========
Item4
Item5
I want to use cucumber + capybara to run feature test and verify that the page has correct content. How would I do that as simple as possible? Since I want to make sure that each item has ended up under the correct headline.
My first attempt was by using
page.should have_content"Headline1
=========
Item1
Item2
Item3
Headline2
=========
Item4
Item5"
But that gives me a strange error:
expected there to be content "Headline1\n=========\nItem1\n and so on" in "Headline1\n=========\nItem1\n and so on"
In other words the two lines is exactly the same!!! Why does this not work? Any workaround? Note that the page contains of only basic text so no div items or such that I can check within.
Use page.text with include? or match methods.
http://robots.thoughtbot.com/post/8399836754/multiline-strings-in-capybara http://praktikanten.brueckenschlaeger.org/2011/11/15/working-in-cucumber-with-new-lines-and-have_content
A quote from the first link:
When checking for a multiline string in Capybara, you need to use page.text because page.source does not preserve new lines - so “a\nb” would come out as “a b” in page.source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With