Screenshots of selenium using rspec

I am trying to capture screenshots when a test fails using selenium-client and rspec. I ran this command:

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

It correctly creates a report when everything passes, since screenshots are not required. However, when the test fails, I get this message, and the report has blank screenshots:

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

What causes the "expired expired" error? Am I missing something important in my specification? Here is the code for 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
+3
source share
5 answers

To get screenshots when working with an error, I had to change things a bit.

spec_helper ( C:\Ruby\lib\ruby ​​\ gems\selenium-client-1.2.18\lib\selenium\rspec\spec_helper.rb):

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

append_after (: each) / ( @selenium_driver.close_current_browser_session).

, !

0

, - . , : after_each 10 , : timeout_in_seconds = > 2000

+1

after, ?

0

".

it "backed up" do
    page.open "/SQLDBDetails.aspx
0

Source: https://habr.com/ru/post/1724313/


All Articles