首页 > 解决方案 > 当我在 rspec 测试中使用 Watir.default_timeout 时,它似乎不起作用

问题描述

我需要延长@page.run_asset上的等待时间,因为完成该过程可能需要超过 30 秒的时间。所以我找到了 Watir.default_time 并将其添加到我的代码中。当我运行测试时,它仍然失败并显示与以前相同的错误:

失败/错误:@page.run_asset Selenium::WebDriver::Error::ScriptTimeOutError:脚本超时:30 秒内未收到结果

it 'expects table action to succeed' do
  Watir.default_timeout = 180
  @page.debug_asset(table_name)
  @page.select_sample(sample)
  @page.run_asset
  expect(@page.return_to_input_element.present?).to be true
end

我尝试实现以下代码并显示相同的错误。

it 'expects table action to succeed' do
  wait = Selenium::WebDriver::Wait.new(timeout: 150)
  @page.debug_asset(table_name)
  @page.run_asset
  field_displayed = wait.until { 
  @asset_debugger_page.return_to_input_element.present? }
  expect(@page.return_to_input_element.present?).to be true
end

我环顾四周,似乎找不到一个好的答案。任何帮助,将不胜感激。

谢谢

标签: rspecwatir

解决方案


Watir 超时时间是 Watir 将等待元素出现或变为存在的时间,而不是等待页面加载、脚本执行或网络读取的时间。您想在功能中设置脚本超时

这是在 Watir 中增加脚本超时的方法:

browser = Watir::Browser.new(:chrome, timeouts: {script: 60000})

推荐阅读