如何使用rpsec修复Ruby中Selenium Webdriver中的执行过期

时间:2017-06-29 09:16:20

标签: ruby-on-rails ruby selenium

我正在尝试运行一个测试,回答在angularjs中完成的表单。 当我运行测试时,经过一段时间后,我不断收到如下错误。我试图用StandardError捕获异常,但我想找到解决这个问题的方法。

  • Ruby: ruby​​ 2.1.5p273(2014-11-13修订版48405)[i386-mingw32]
  • Selenium: SeleniumServerStandalone-2.47.1.jar和SeleniumServerStandalone-3.4.0.jar

(我已经尝试过Selenium Server以查看最新的Selenium Server是否会在没有运气的情况下修复它。)

Failure/Error: base_question.complete
         Timeout::Error:
           execution expired
         # ./lib/api/page_model.rb:175:in 'sleep'
         # ./lib/api/page_model.rb:175:in 'block in until'
         # C:/Ruby21/lib/ruby/2.1.0/timeout.rb:91:in 'block in timeout'
         # C:/Ruby21/lib/ruby/2.1.0/timeout.rb:35:in 'block in catch'
         # C:/Ruby21/lib/ruby/2.1.0/timeout.rb:35:in 'catch'
         # C:/Ruby21/lib/ruby/2.1.0/timeout.rb:35:in 'catch'
         # C:/Ruby21/lib/ruby/2.1.0/timeout.rb:106:in 'timeout'
         # ./lib/api/page_model.rb:170:in 'until'
         # ./lib/api/ais_page_model.rb:951:in 'answer'
         # ./lib/api/ais_page_model.rb:812:in 'complete'
         # ./lib/api/ais_page_model.rb:676:in 'complete'
         # ./spec/core/ui/multithread/answers.rb:178:in 'block (2 levels) in <top (required)>'
         # ./lib/patches/rspec.rb:24:in 'instance_eval'
         # ./lib/patches/rspec.rb:24:in 'block in run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:253:in 'with_around_each_hooks'
         # ./lib/patches/rspec.rb:21:in 'run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:378:in 'block in run_examples'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in 'map'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in 'run_examples'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:360:in 'run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in 'block (2 levels) in run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in 'map'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in 'block in run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:34:in 'report'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in 'run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in 'run'
         # C:/Ruby21/lib/ruby/gems/2.1.0/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in 'block in autorun'

第175行的代码

def until
  raise NestedWaitCallError if Kernel.caller.any? { |caller| caller.include?(__method__.to_s) }
  raise "no block given" unless block_given?
  Timeout::timeout(self) do
    delay = 0.1
    begin
     until yield
       sleep delay
       delay *= 2
     end
     rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::StaleElementReferenceError
     sleep delay
     delay *= 2
     retry
    end
  end
end

0 个答案:

没有答案