Testing the list is sorted in the correct order capybara

I am trying to write some tests in capybara that will check a list of dates, sorted correctly. For example, I have a list of dates Wed Jun 27, Mon 13 Aug 12, Thu May 31, 12, and when I click on the button, it will change the dates starting from the earliest, i.e.: Thu May 31, 12, Wed. June 27, August 12, 13.

Is there a way in capybara so you can write such tests.

Normally I would use methods like page.find, etc., but these methods will simply find the dates and not tell if they were sorted in the correct order.

+8
ruby-on-rails selenium automated-tests rspec capybara
source share
1 answer

You need to use the selector :nth-child css.

#dates your date list is in <ul> with id #dates , you can check the order with:

 page.should have_selector("ul#dates li:nth-child(1)", content: @date1.content) page.should have_selector("ul#dates li:nth-child(2)", content: @date2.content) 

The first value passed to have_selector() is your selector, the second (in this example) is what you expect. You are not limited to only passing content, for example, if each date is associated with a Date#show action, which you could add url: date_path(@date) .

+15
source share

All Articles