栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

是否可以全局增加Watir-Webdriver when_present等待时间?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

是否可以全局增加Watir-Webdriver when_present等待时间?

更新 :此猴子补丁已合并到watir-webdriver中,因此在watir-webdriver
v0.6.5中将不再需要。您将可以使用以下命令设置超时时间:

Watir.default_timeout = 90

在等待的方法是类似这样定义的:

def when_present(timeout = 30)  message = "waiting for #{selector_string} to become present"  if block_given?    Watir::Wait.until(timeout, message) { present? }    yield self  else    WhenPresentDecorator.new(self, timeout, message)  endend

如您所见,默认的30秒超时是硬编码的。因此,没有简单的方法可以在任何地方进行更改。

但是,您可以猴子修改wait方法以使用默认时间并将其设置为所需的时间。以下猴子补丁会将默认超时设置为90秒。

require 'watir-webdriver'module Watir  # Can be changed within a script with Watir.default_wait_time = 30      @default_wait_time = 90    class << self    attr_accessor :default_wait_time      end  module Wait    class << self      alias old_until until      def until(timeout = Watir.default_wait_time, message = nil, &block)        old_until(timeout, message, &block)      end      alias old_while while      def while(timeout = Watir.default_wait_time, message = nil, &block)        old_while(timeout, message, &block)      end    end # self  end # Wait  module EventuallyPresent    alias old_when_present when_present    def when_present(timeout = Watir.default_wait_time, &block)      old_when_present(timeout, &block)    end    alias old_wait_until_present wait_until_present    def wait_until_present(timeout = Watir.default_wait_time)      old_wait_until_present(timeout)    end    alias old_wait_while_present wait_while_present    def wait_while_present(timeout = Watir.default_wait_time)      old_wait_while_present(timeout)    end  end # EventuallyPresentend # Watir

加载watir Webdriver代码后,请包括补丁。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/430771.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号