【问题标题】:Retry testing sites after timeout error in Watir在 Watir 出现超时错误后重试测试站点
【发布时间】:2013-04-13 05:07:11
【问题描述】:

我正在浏览一个站点列表,并使用 Watir 访问每个站点以在每个页面的源代码中查找某些内容。但是,在大约 20 或 30 个站点之后,浏览器在加载某个页面时超时并且它破坏了我的脚本,我收到了这个错误:

rbuf_fill: 执行过期(Timeout::Error)

我正在尝试实施一种方法来检测它何时超时,然后从它停止但遇到问题的地方重新开始测试站点。 这是我的代码:

ie = Watir::Browser.new :firefox, :profile => "default"
testsite_array = Array.new
y=0
File.open('topsites.txt').each do |line|
testsite_array[y] = line
y=y+1
end
total = testsite_array.length
count = 0
begin
    while count <= total
        site = testsite_array[count]
        ie.goto site
        if ie.html.include? 'teststring'
            puts site + ' yes'
        else
            puts site + ' no'
        end

rescue
retry
    count = count+1
    end
end
ie.close

【问题讨论】:

  • 当您说“重新开始测试站点”时,您的意思是要跳过失败的站点并继续下一个站点吗?或者您想重试失败的站点,然后继续下一个站点?
  • 我想重试失败的站点,然后继续下一个!这将解决超时错误问题。下线,如果站点多次失败,例如在域名不存在的情况下,我想实现跳过站点!

标签: ruby timeout watir rescue


【解决方案1】:

您的循环可以是:

#Use Ruby's method for iterating through the array
testsite_array.each do |site|
    attempt = 1
    begin
        ie.goto site
        if ie.html.include? 'teststring'
            puts site + ' yes'
        else
            puts site + ' no'
        end 
    rescue
        attempt += 1

        #Retry accessing the site or stop trying
        if attempt > MAX_ATTEMPTS
            puts site + ' site failed, moving on'
        else
            retry
        end
    end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多