I am testing with RSpec + Capybara + Selenium (Firefox). No matter what subset of my acceptance tests I run, the first one fails (next tests do work correctly) with "reason" like this:
Failure/Error: visit '/'
Timeout::Error:
Timeout::Error
My application relies on GoogleMaps and BackboneJS heavily. When I run tests, page does not finish to load and "transferring data from maps.googleapis.com" message stays in bottom-left of Firefox window, however page looks like it loaded properly (maps and other content are present). I've already set timeout to 60 secs to exclude any slow network problems. And all the subsequent tests do work very fast (like proper Google scripts were fetched and are already cached). Also when I start server in development environment and access it (localhost:3000
) everything works fine.
Firefox 17.0.1. Some of my gems:
capybara (2.0.1)
database_cleaner (0.9.1)
mongoid (3.0.13)
rspec (2.12.0)
rspec-core (2.12.1)
rspec-expectations (2.12.0)
rspec-mocks (2.12.0)
rspec-rails (2.12.0)
selenium-webdriver (2.26.0)
Do you have any idea why this happens and how to prevent it?
EDIT:
spec/spec_helper.rb
:
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.treat_symbols_as_metadata_keys_with_true_values = true config.infer_base_class_for_anonymous_controllers = false #config.order = "random" end
spec/features/features_spec_helper.rb
:
require_relative "../spec_helper" require 'capybara/rspec' Capybara.default_driver = :selenium Capybara.default_wait_time = 60
EDIT2:
It used to work properly before (few weeks ago; this project was halted for that time). Could be introduced by RSpec upgrade from 2.11 to 2.12 (which I did those few weeks ago), but I've just tried to downgrade it and same things do happen. I've reverted whole codebase to the point month ago to exclude possible gem regression. Problem still happens.
EDIT3:
I've just discovered that if I comment out the line responsible for attaching map from Google:
new google.maps.Map($("#map")[0], mapOptions)
then everything works like a charm.
EDIT4:
Source code of example application: https://github.com/skalee/capybara-google-maps-failure
Running all specs will result with Timeout::Error in the first one (at least for me). However, all specs will pass when:
#map{ width: 600px ; height: 600px }
Gems are exactly the same gems as I use in my app. There are some 3rd party scripts in /vendor/assets
.
You should not depend on external services for your tests. Here is a strategy:
http://robots.thoughtbot.com/post/34761570235/using-capybara-to-test-javascript-that-makes-http
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With