Sha256: b6e5f6e055ead49a79453e98793d7f4d691cf8f636da9cfc285bc915da95171a

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

# This code is made by Jari Bakken @ https://gist.github.com/1b14247aae08a7e93f54
#
# Added wait_until? and wait_while? methods and reduced sleeping time to 0.1 secs
module Watir
  module WaitHelper
    extend self

    class TimeoutError < StandardError
    end

    #
    # Wait until the block evaluates to true or times out.
    #

    def wait_until(timeout = 60, &block)
      end_time = ::Time.now + timeout

      until ::Time.now > end_time
        result = yield(self)
        return result if result
        sleep 0.1
      end

      raise TimeoutError, "timed out after #{timeout} seconds"
    end

    #
    # Wait while the block evaluates to true or times out.
    #

    def wait_while(timeout = 60, &block)
      end_time = ::Time.now + timeout

      until ::Time.now > end_time
        return unless yield(self)
        sleep 0.1
      end

      raise TimeoutError, "timed out after #{timeout} seconds"
    end
  end # WaitHelper
end # Watir

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
watirsplash-0.2.14 lib/watirsplash/wait_helper.rb
watirsplash-0.2.12 lib/watirsplash/wait_helper.rb
watirsplash-0.2.11 lib/watirsplash/wait_helper.rb
watirsplash-0.2.10 lib/watirsplash/wait_helper.rb
watirsplash-0.2.9 lib/watirsplash/wait_helper.rb