gpt4 book ai didi

ruby-on-rails - 什么会导致 Capybara::Poltergeist::TimeoutError: 在不单独进行的组测试中?

转载 作者:行者123 更新时间:2023-12-04 16:21:10 24 4
gpt4 key购买 nike

一个 Rails 应用程序,它使用远程测试来测试在 Vagrant Ubuntu VM 上运行的 CakePHP 应用程序。
我的操作系统是 macOS High Sierra。

'rspec/rails'
'capybara/rails'
'capybara/mechanize'
'capybara/poltergeist'
'phantomjs'

如果我运行 rspec ./spec/features/my_tests_folder/ ,
文件夹中的前 2 个测试总是通过,其余的总是以 Capybara::Poltergeist::TimeoutError: 结束。 .

如果我单独运行该文件夹中的任何测试,它们总是通过。

总共有7个测试文件。它们每个都有 1 个功能和 1 个场景。都是 js: true .

我试过增加 :timeoutCapybara.register_driver并增加 default_max_wait_timeCapybara.configure .两者都没有改变结果。

我也玩过 Capybara.reset!每次考试前后。这似乎也无关紧要。

当我用 config.order = :random 运行它时,有时 7 个中有 5 个有错误,有时 7 个中只有 2 个。但是,总是有一些错误和一些通过。此外,每个测试至少一次在错误组中。

我的想法不多了。什么会导致这样的事情?

更新(包括 Capybara 和 Poltergeist 配置以及失败测试的示例):

rails_helper.rb 中的配置:
Capybara.register_driver :poltergeist do |app|
options = {
:timeout => 90, # default is 30
:js_errors => false,
:phantomjs => Phantomjs.path,
# :debug => true
}
Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.register_driver :mechanize do |app|
driver = Capybara::Mechanize::Driver.new(app)
driver.configure do |agent|
agent.user_agent_alias = 'Mac Safari'
end

driver
end

Capybara.configure do |config|
config.run_server = false
config.app_host = "http://my_vm_domain.com"
config.javascript_driver = :poltergeist
config.default_driver = :mechanize
config.default_max_wait_time = 10 # default is 2
end

失败测试的例子(不是失败,而是得到 Capybara::Poltergeist::TimeoutError: ):
require 'rails_helper'

feature 'agente visualiza estoques de um passeio', js: true do

scenario 'com sucesso' do

agente_log_in

visit '/roteiro/show/723'

find(:partial_href, 'new_passeio/723').click

select 'Passeio Teste', from: 'passeio_produto'
fill_in 'passeio_data', with: '11/11/2017'

within('button#estoque_controls_0') do

within('div#estoque_0_hora') do
expect(page).to have_content('07:30')
end

within('span#estoque_0_vagas') do
expect(page).to have_content('3')
end

end

within('button#estoque_controls_1') do

within('div#estoque_1_hora') do
expect(page).to have_content('10:00')
end

within('span#estoque_1_vagas') do
expect(page).to have_content('5')
end

end

end

end

代码来自 agente_log_in.rb在支持文件夹中:
def agente_log_in

Capybara.app_host = "http://my_vm_domain.com"

visit '/usuario/logout'
visit '/'

fill_in 'data[AdmUsuario][usuario]', with: 'agente'
fill_in 'data[AdmUsuario][senha]', with: 'pa$$w0rd'

click_on 'Entrar'

end

代码 :partial_href找:
module Selectors

Capybara.add_selector(:partial_href) do
xpath {|href| XPath.descendant[XPath.attr(:href).contains(href)] }
end

end

应用程序的其他文件夹中的其他测试一切正常。如果我单独运行此文件夹中的测试,它们也很好。这个问题似乎只有在我整体运行这个特定文件夹时才会发生。

最佳答案

在包含 Thomas Walpole 要求的额外信息后,我继续搜索和研究可能性。

我最终遇到了poltergeist's issue #781 on GitHub ,它描述的情况与我的非常相似,并最终呈现了 wait_for_ajax solution .

在我的项目中实现它之前,我阅读了更多关于等待 Ajax 的内容,发现 this post也很有帮助。

最后,我从 GitHub 上选择了 jasonfb 的代码,因为它看起来更全面和信息量更大。

它就像一个魅力!我的测试现在一直通过。我什至能够删除 :timeout 的自定义设置和 default_max_wait_time .

有问题的 CakePHP 应用程序非常重 js,并且该文件夹测试的特定部分特别充满了 Ajax 请求。

关于ruby-on-rails - 什么会导致 Capybara::Poltergeist::TimeoutError: 在不单独进行的组测试中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50110877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com