Sleep function in Capybara / Cucumber?

I have a page on my site that I am trying to check, which requires the user to spend at least five seconds on the page before continuing. Is there a way with Capybara that my cucumber tests stop on this page and wait five seconds before proceeding to the next step that I am describing?

+7
source share
2 answers

I have this in my step definitions:

Given /^I wait for (\d+) seconds?$/ do |n| sleep(n.to_i) end 

In your function:

 Given I am on the whatever page And I wait for 5 seconds And I follow "A Link" # etc... 
+21
source

It would also be great to define a dynamic unit of time like this:

 Given /^I wait for (\d+) (second|minute|hour)s?$/ do |n, unit| sleep(eval("#{n.to_i}.#{unit}")) end 
+1
source