Mike Grace
Mike Grace

Reputation: 16924

Only run selenium test if previous selenium test fails

I have several 'it' blocks in my selenium test file (using Ruby and rspec) that test various portions of my web application. Each 'it' block stops executing and goes to the next 'it' block if any of the conditions or code fails.

Example 'it' block

it "should load example.com" do
  page.open("http://example.com")
  page.wait_for_page_to_load(25)
end

Upvotes: 3

Views: 224

Answers (1)

Mike Grace
Mike Grace

Reputation: 16924

I don't like my current solution and think there is a better way to accomplish this, but for now...

  • wrap original test code that was in the 'it' block in a begin rescue block
  • put code to respond to failure in the rescue section

.

it "should load example.com" do
  begin
    page.open("http://example.com")
    page.wait_for_page_to_load(25)
    "wow".should == "cool"
  rescue Exception => e
    // code that responds to failed test
  end
end

Why I don't like this

  • I feel dirty writing test code like this (it feels wrong!)
  • The rspec reports a pass unless the rescue code also fails

Upvotes: 1

Related Questions