开发者

Only run selenium test if previous selenium test fails

开发者 https://www.devze.com 2023-02-03 06:47 出处:网络
I have several \'it\' blocks in my selenium test file (using Ruby and rspec) that test va开发者_如何学JAVArious portions of my web application. Each \'it\' block stops executing and goes to the next \

I have several 'it' blocks in my selenium test file (using Ruby and rspec) that test va开发者_如何学JAVArious 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.

  • Is there a way to run an 'it' block only if the previous fails or call a function to react to the failed test?
  • Is there a better way to accomplish what I am wanting to do that doesn't involve an 'it' block?

Example 'it' block

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号