问题
I'm using selenium, capybara with rspec for testing, i noticed all tests pass locally, but on travis all tests fail with this error on each spec.
Capybara::ElementNotFound:
I'm not sure what is wrong here, here is the specs runner on .travis.yml
script:
- xvfb-run bundle exec rspec spec/features/*.rb
for spec_helper.rb here is my config:
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.use_transactional_fixtures = false
config.infer_base_class_for_anonymous_controllers = false1
config.filter_run_excluding :broken => true
config.render_views
Capybara.default_driver = :selenium
Capybara.default_selector= :css
Capybara.run_server = true
Capybara.default_wait_time = 30
回答1:
Well I found the reason of the issue and the solution.
Reason: We use responsive design, and apparently travis uses a small window size which turned on the mobile design and that is why it couldn't find the elements.
Solution:
script:
- xvfb-run --server-args="-screen 0 1024x768x24" bundle exec rspec spec/features/*.rb
You basically set windows size to a larger size.
来源:https://stackoverflow.com/questions/20713471/capybaraelementnotfound-on-all-specs-only-on-travis