13
votes

I have a page on my site that I'm trying to test that requires that a user spend at least five seconds on the page before proceeding. Is there a way with Capybara to get my Cucumber tests to pause on that page and wait five seconds before proceeding with the next step I describe?

2

2 Answers

30
votes

I have this in my step definitions:

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

In your feature:

Given I am on the whatever page
And I wait for 5 seconds
And I follow "A Link"
# etc...
1
votes

It would be also great to define dynamically the time unit like this one :

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