我试图捕获使用硒的客户端和RSpec上测试失败屏幕截图。我运行此命令:

$ spec my_spec.rb \
--require 'rubygems,selenium/rspec/reporting/selenium_test_report_formatter' \
--format=Selenium::RSpec::SeleniumTestReportFormatter:./report.html 

它正确地创建报告时,一切都通过,因为不需要的屏幕截图。然而,当测试失败,我得到这个消息,报告中有空白屏幕截图:

WARNING: Could not capture HTML snapshot: execution expired
WARNING: Could not capture page screenshot: execution expired
WARNING: Could not capture system screenshot: execution expired
Problem while capturing system stateexecution expired

是什么原因造成“执行过期”的错误?我失去了我的天赋重要的东西?下面是my_spec.rb的代码:

require 'rubygems'
gem "rspec", "=1.2.8"
gem "selenium-client"
require "selenium/client"
require "selenium/rspec/spec_helper"

describe "Databases" do
    attr_reader :selenium_driver
    alias :page :selenium_driver

  before(:all) do
      @selenium_driver = Selenium::Client::Driver.new \
          :host => "192.168.0.10",
          :port => 4444,
          :browser => "*firefox",
          :url => "http://192.168.0.11/",
          :timeout_in_seconds => 10
  end

  before(:each) do
    @selenium_driver.start_new_browser_session
  end

  # The system capture need to happen BEFORE closing the Selenium session
  append_after(:each) do
    @selenium_driver.close_current_browser_session
  end

  it "backed up" do
    page.open "/SQLDBDetails.aspx"
    page.click "btnBackup", :wait_for => :page
    page.text?("Pending Backup").should be_true
  end
end
有帮助吗?

解决方案

为了得到工作,我不得不国防部东西就差错的截图了一下。

我提出下列代码出spec_helper的(我发现在C:\红宝石\ lib中\红宝石\宝石\硒 - 客户1.2.18 \ lib中\硒\ rspec的\ spec_helper.rb):

    if actual_failure?
         Selenium::RSpec::SeleniumTestReportFormatter.capture_system_state(selenium_driver, self)
    end

和放置入append_after(:每个)。我的做试验的建立/拆除的部分(线@ selenium_driver.close_current_browser_session之前)

希望这有助于!

其他提示

我遇到了这个问题,并能够通过设置超时时间为驾驶员解决它。 这可能会导致驱动程序运行到之前结束浏览器会话:after_each 您使用的10秒,我运行细跟:timeout_in_seconds => 2000

为什么不采取截图的功能后,但你关闭浏览器之前?

,它看起来像缺少"那里。

it "backed up" do
    page.open "/SQLDBDetails.aspx
scroll top