我試圖捕捉使用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)釋放時,屏幕截圖仍然不起作用。 –