1

Here's what I'm currently doing:

  def wait_for(timeout = 5)
    Selenium::WebDriver::Wait.new(:timeout => timeout).until { yield }
            rescue Selenium::WebDriver::Error::TimeOutError => e
            puts 'Timeout Error'
            rescue Selenium::WebDriver::Error::NoSuchElementError => ex
            puts 'No Such Element Error'
  end

Two questions:

1) Why is it showing me the Timeout Error twice? It should just time out and end the test

2) How do I get it to not show me all that extra information at the bottom? Ideally what I'd like is just for it to say "Timeout" or "No such element" and that's it.**

My log spits out alllll of this:

Loaded suite C:/2oh/qt Started

First Run Timeout Error Timeout Error E ======================================================================================================================================================================================================== Error: test_18a(Tests):
Selenium::WebDriver::Error::NoSuchElementError: no such element (Session info: chrome=43.0.2357.134) (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 x86_64) C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/response.rb:71:in assert_ok' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/response.rb:34:in initialize' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:78:in new' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:78:in create_response' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/default.rb:90:in request' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:59:in call' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:657:in raw_execute' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:635:in execute' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:603:in find_element_by' C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/search_context.rb:61:in find_element' C:/2oh/qttests.rb:28:in test_hdesrbf' C:/2oh/qt.rb:13:intest_18a' 10: 11: def test_18a 12: puts "First Run" => 13: test_hdesrbf 14: end
15:
16:

Jen
  • 109
  • 1
  • 12

1 Answers1

1

The output you are seeing is telling you more information about the error you are rescuing. Don't think there is any escaping it, although it is handy because it will tell you what line of code has failed, and why. I'm not actually 100% sure why you would want to simplify the error!

The reason you are seeing the errors twice is because you are not telling the program to end. You are saying 'Hey, rescue this error type and output this text.' you're not telling it to stop. It will continue and I guess timeout finding the next element? To rectify this, instead of using puts to output your error text, use raise. This will halt the program once the text has been output. E.g

def wait_for(timeout = 5)
  Selenium::WebDriver::Wait.new(:timeout => timeout).until { yield }
  rescue Selenium::WebDriver::Error::TimeOutError
    raise 'Timeout Error'
  rescue Selenium::WebDriver::Error::NoSuchElementError
    raise 'No Such Element Error'
end
David Ambler
  • 133
  • 1
  • 1
  • 9
  • The thing is that there is only one point of failure, I know which line it is. I use this to output to a text file that I automatically email out to less technical folks so I'd like to simplify it so they just know that the test timed out. Also thank you so much for raise fix, definitely fixed that. I wasn't sure what the difference is, I'm glad to have learned that. Much appreciated! – Jen Aug 10 '15 at 17:49
  • No problem! Check out http://stackoverflow.com/questions/2777802/how-to-write-to-file-in-ruby regarding outputting to a text file. You could do your write action before your raise. The console would still output the full error, but you can output whatever you want to the text file! – David Ambler Aug 11 '15 at 08:11