Watir:抑制对象超时以支持我自己的错误

时间:2014-10-11 17:29:57

标签: ruby watir error-suppression

我正在使用一个处理数百个测试用例的自动化框架,一旦编写了所有脚本,就会有数千个。正在测试的应用程序有一个错误页面,当出现内部错误时会显示该错误页面,这会导致我们正常的对象超时友好错误,因为Watir无法找到有问题的对象:

  1) Error:
Test_Case#test_case:
Watir::Wait::TimeoutError: timed out after 30 seconds, waiting for {:xpath=>"//small[@class=\"total-card-value\"]"} to become present
    C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.11/lib/watir-webdriver/wait.rb:48:in `until'
    C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.11/lib/watir-webdriver/wait.rb:120:in `method_missing'
    C:/workspace/Automated_Test_Scripts/trunk/Phoenix/classes/sidebar.rb:85:in `get_total_card_value'
    C:/workspace/Automated_Test_Scripts/trunk/Phoenix/classes/sidebar.rb:65:in `check_total'
    C:/workspace/Automated_Test_Scripts/trunk/Phoenix/tests/Reloadable_Payment.rb:116:in `block in test_case'
    C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ruby-mysql-2.9.12/lib/mysql.rb:675:in `call'
    C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ruby-mysql-2.9.12/lib/mysql.rb:675:in `each'
    C:/workspace/Automated_Test_Scripts/trunk/Phoenix/tests/Reloadable_Payment.rb:50:in `test_case'

此Watir错误无法准确地告诉我测试执行期间发生了什么,因为在此示例中页面重定向到错误页面。我想解除我的日志,并防止显示Watir错误,而是显示自定义错误消息:

  if $b.text.include?("We're sorry, but something went wrong.")
    puts "\033[1;31;40m Phoenix has stopped responding and is showing the \"We're sorry...\" message. Please e-mail these test log steps to the Phoenix group.\033[0m"
  end

当我将其添加到拆解(Minitest :: Unit)时,它会按照我的预期显示,但它也会显示超时错误,无论我根据其他示例尝试进行错误的页面加载。

当我想在日志中显示此特定错误时,如何抑制对象超时错误?

0 个答案:

没有答案