Skip to content

Instantly share code, notes, and snippets.

@anoras
Created May 7, 2013 20:42
Show Gist options
  • Save anoras/5535945 to your computer and use it in GitHub Desktop.
Save anoras/5535945 to your computer and use it in GitHub Desktop.
Strange intermittent failures with Capybara. Always fails on CI server, sporadically fails in development environment, but never at the same assertion as on the CI server. Any clues why?
describe 'dashboard' do
it 'should be possible to edit an item', js: true do
visit_subdomain 'bizeeme', '/dashboard/'
# The browser app creates the UI with Backbone.js when loaded...
within '#item-list' do # <- It allways fails on the CI server here, because "#item-list" doesn't exist.
find('a', text: /First/i).click
end
within '#content' do
fill_in 'description', with: 'Changed description!'
click_button 'Save'
end
visit '/items'
page.should have_content 'Changed description!' # <- It intermittently fails here in the development environoment.
end
end
1) dashboard should show a list of items
Failure/Error: within '#item-list' do
Capybara::ElementNotFound:
Unable to find css "#item-list"
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/result.rb:22:in `find!'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/finders.rb:26:in `block in find'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/base.rb:78:in `synchronize'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/finders.rb:26:in `find'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/session.rb:341:in `block (2 levels) in <class:Session>'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/session.rb:211:in `within'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./spec/frontend/dashboard/cms_spec.rb:8:in `block (3 levels) in <top (required)>'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara.rb:232:in `using_wait_time'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/dsl.rb:28:in `using_wait_time'
# ./spec/frontend/dashboard/cms_spec.rb:5:in `block (2 levels) in <top (required)>'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `instance_eval'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `block in run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in `run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `map'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `run_examples'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in `run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
# /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
@anoras
Copy link
Author

anoras commented May 7, 2013

When retrofitting wait_until and using that to wait for the element to become visible using:

def wait_until
  require "timeout"
  Timeout.timeout(Capybara.default_wait_time) do
    sleep(0.1) until value = yield
    value
  end
end

..the CI server fails with:

Failure/Error: wait_until { find('#item-list') }
     Timeout::Error:
       execution expired
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/base.rb:84:in `sleep'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/base.rb:84:in `rescue in synchronize'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/base.rb:77:in `synchronize'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/node/finders.rb:26:in `find'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/session.rb:341:in `block (2 levels) in <class:Session>'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/capybara-2.0.3/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./spec/frontend/dashboard/cms_spec.rb:7:in `block (3 levels) in <top (required)>'
     # ./spec/frontend/frontend_helper.rb:40:in `block in wait_until'
     # ./spec/frontend/frontend_helper.rb:39:in `wait_until'
     # ./spec/frontend/dashboard/cms_spec.rb:7:in `block (2 levels) in <top (required)>'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `instance_eval'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `block in run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in `run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in `block in run_examples'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `map'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `run_examples'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in `run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
     # /mnt/home/u1968/bundle/ruby/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

@anoras
Copy link
Author

anoras commented May 10, 2013

I solved this one. It had nothing to do with Capybara. It was caused by a RequireJS path with an uppercase letter in it, while the actual filename was a all lower cased. This worked locally since it was running on Mac OS with the HD formatted as Mac OS Extended (Journaled) rather than Mac OS Extended (Case-sensitive, Journaled). The CI server was running Linux where the filesystem is case sensitive. This caused a HTTP error to occur when RequireJS tried to load the file in CI, while everything worked smoothly locally.
Since this shows up as an HTTP error in the browser console, but not in the browser's console log, it was a hard one to track down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment