Capybara::ElementNotFound 的所有规格仅在 Travis 上

2024-04-20

我正在使用 selenium、capybara 和 rspec 进行测试,我注意到所有测试都在本地通过,但在 travis 上,所有测试都失败,并在每个规范上出现此错误。

Capybara::ElementNotFound:

我不确定这里出了什么问题,这是 .travis.yml 上的规范运行程序

script:
- xvfb-run bundle exec rspec spec/features/*.rb

对于spec_helper.rb,这是我的配置:

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

好吧,我找到了问题的原因和解决方案。

Reason:我们使用响应式设计,显然 travis 使用了较小的窗口尺寸,这开启了移动设计,这就是为什么它找不到元素。

Solution:

script:
- xvfb-run --server-args="-screen 0 1024x768x24" bundle exec rspec spec/features/*.rb

您基本上将窗口大小设置为更大的尺寸。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Capybara::ElementNotFound 的所有规格仅在 Travis 上 的相关文章

随机推荐