Apparently, sleep
or wait_until
are not valid using recent versions of Capybara, according to the webpage updates.
However, I have a set of tests that only work on fast machines if I add a sleep(1)
call to the test. That is, a test that looks like:
describe "dosimeters page" do
before do
click_link("Dosimeter Read History", :match=>:first)
end
...
becomes
describe "dosimeters page" do
before do
unix_wait
click_link("Dosimeter Read History", :match=>:first)
end
...
where I've defined unix_wait
as:
def unix_wait
case RbConfig::CONFIG['host_os']
when /darwin/
when /linux-gnu/
sleep(1)
end
end
The thing is, I have an old Ubuntu 12.04 quadcore laptop running these tests on Jenkins, and everything works well on it without the unix_wait
calls. The tests failed randomly on a hexacore desktop running Ubuntu 13.10 and on a macbook pro laptop, but if I add in the unix_wait
call, then the tests pass.
The test failures themselves are indicative of loading failures (ie, css elements missing on some runs, but not on others), and the things being tested actually work when the site is loaded manually.
So what's the appropriate action here? Apparently, sleep
isn't allowed during testing, nor is wait_until
. However, sleep is working, but it does seem extremely crude to me. Should I be looking at #synchronized
? From what I gather from those blog posts, that's already getting called when I call click_link
, and the tests are still failing.
What is the accepted protocol here?
I should add, because I think it's important: These are all javascript tests. I'm using capybara-webkit built on qt4 (not qt5). I'm considering switching to poltergeist or some other javascript driver as a debug step.
sleep
is not valid in Capybara. In fact, that would be very strange since it's a Ruby function and not part of the Capybara DSL. – Boardingsleep
is valid, but they're trying to make the point that it shouldn't be necessary, with the suggestion that it may be bad style. With that in mind, I'm trying to figure out how to make tests that are both good style and pass when they should pass. – Distinctionfind
on the page as, per the docs,find
waits until it has the element on the page before executing... – Courtyardclick_link
inbefore do
fails with a message that it can't find the link to click. Adding a wait means that it can find the link. @CDub-- as per the docs,click_link
should do the same thing, but it clearly does not. – Distinctionputs Capybara.default_wait_time
directly before your assertion? 3) How long does the test take to fail? 4) What in your code causes this element to appear after the initial page load? – Lynnelynnea