【问题标题】:No terminal output with caypbara / rspec / selenium-webdrivercaypbara / rspec / selenium-webdriver 没有终端输出
【发布时间】:2014-11-24 20:46:33
【问题描述】:

我一直在使用 capybara 和 selenium-webdriver 编写 rspec 测试。几乎没有失败,每当我运行这些测试之一时,控制台输出都会消失。

例如:

~/code/code> bundle exec rspec spec/features/interactions_spec.rb 

InteractionsSpec
~/code/code> 

这就是我所见过的一切。浏览器启动,执行我编写的操作,但我没有看到通常的输出。

有时我会将其视为输出(耶!):

InteractionsSpec
  login as admin works
  login as user works

Finished in 16.84 seconds (files took 7.9 seconds to load)
2 examples, 0 failures

什么可能导致测试的输出消失?这使得编写测试几乎不可能 - 因为我不知道什么已经运行,什么已经通过,什么失败了,或者为什么他们失败了。

我正在使用这些 Gem,但执行包更新不会改变行为。

  • 水豚 (2.4.4)
  • 水豚截图 (1.0.3)
  • rspec (3.0.0)
  • rspec-activemodel-mocks (1.0.1)
  • rspec-collection_matchers (1.0.0)
  • rspec-core (3.0.3)
  • rspec 期望 (3.0.3)
  • rspec 模拟 (3.0.3)
  • rspec-rails (3.0.2)
  • rspec 支持 (3.0.3)
  • selenium-webdriver (2.44.0)
  • 应该匹配器 (2.6.2)

其他涉及的软件:

  • Firefox 33.1.1(Chrome 39.0.2171.65(64 位)具有相同的行为)
  • OSX 10.9.5
  • Rails 4.1.4

更新 这似乎解决了一段时间的问题,即使睡眠时间为 1 毫秒。但是,这只是一个临时修复,此问题仍然存在。

RSpec.configure do |config|
  config.before(:each, :type => :feature) do
    sleep(0.5)
  end
end

【问题讨论】:

  • 我尝试过的一些事情:重新安装 ruby​​ 和所有 gem、升级 chrome、升级 chrome 驱动程序、更改每个规范之前的睡眠(随机、长、短)

标签: ruby-on-rails rspec selenium-webdriver capybara


【解决方案1】:

在我看来,记录器通过调用 logger.silence() 被其他线程静音。

当您将 sleep() 放入代码中时,您会屈服于其他一些修复日志记录级别的线程 - 这就是为什么不管睡眠多长时间,解决问题的是上下文切换.

当您升级 activesupport gem 时,此提交 https://github.com/rails/activerecord-session_store/commit/f92d1135fc620cb4d65239ef286b267945bbbbc6 修复了问题(如您所说)。阅读该提交,请注意 logger.silence 的新线程安全实现。这就是它解决您的问题的原因。

这里的 active_support/logger_silence.rb 的旧实现不是线程安全的:

require 'active_support/concern'

module LoggerSilence
  extend ActiveSupport::Concern

  included do
    cattr_accessor :silencer
    self.silencer = true
  end

  # Silences the logger for the duration of the block.
  def silence(temporary_level = Logger::ERROR)
    if silencer
      begin
        old_logger_level, self.level = level, temporary_level
        yield self
      ensure
        self.level = old_logger_level
      end
    else
      yield self
    end
  end
end

【讨论】:

  • 我被这个问题弄疯了。感谢 Rob,$ bundle update activerecord-session_store 为我解决了这个问题。
【解决方案2】:

在使用多个线程的 capybara 下初始化 rails 环境时似乎存在许多与线程安全和竞争条件相关的问题。 Rob 的回答解释了它开始工作的原因(日志记录被固定为在 activerecord-session_store 中保存线程)。

看来这些issues和commits也有关系

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    相关资源
    最近更新 更多