我试图捕捉使用selenium-client和rspec的测试失败截图。我运行这个命令:使用rspec的Selenium屏幕截图
$ 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
这种更为玩弄后,我发现截图的工作,如果我删除“@ selenium_driver.close_current_browser_session”来自append_after(:each)。但是,这让我有一堆浏览器窗口被打开,因为没有会话被释放。我尝试在之前(:each)之前释放它们,而不是之后(:each),但当会话在之前(:each)释放时,屏幕截图仍然不起作用。 –