English 中文(简体)
Selenium screenshots using rspec
原标题:

I am trying to capture screenshots on test failure using selenium-client and rspec. I run this command:

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

It creates the report correctly when everything passes, since no screenshots are 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 is causing this execution expired error? Am I missing something important in my spec? 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
最佳回答

In order to get screenshots on error working I had to mod things a bit.

I moved the following code out of spec_helper (which I found in C:Rubylib ubygemsselenium-client-1.2.18libselenium specspec_helper.rb):

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

and placed it into the append_after(:each) do section of my test s setup/teardown (before the line @selenium_driver.close_current_browser_session).

Hope this helps!

问题回答

I ran into that issue and was able to solve it by setting up the timeout for the driver. This can cause the Driver to end the Browser session before running into :after_each You are using 10 seconds, i am running fine with :timeout_in_seconds => 2000

Why not take the screenshot in the after function, but before you close the browser?

Not sure if this would help, https://github.com/mattheworiordan/capybara-screenshot, although it s for Capybara and not Selenium

it looks like missing a " there.

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




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签