Sha256: 33eb4491c35f11e952857e01d4a6163ce66879c247138a991c8aef937dbd9325

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require 'selenium-webdriver'

module Aranha
  module Selenium
    class Session < ::SimpleDelegator
      module Wait
        WAIT_DEFAULT_TIMEOUT = 15

        def wait(timeout = nil)
          timeout ||= wait_default_timeout
          ::Selenium::WebDriver::Wait.new(timeout: timeout)
        end

        def wait_default_timeout
          WAIT_DEFAULT_TIMEOUT
        end

        def wait_for_click(find_element_args, timeout = nil)
          wait(timeout).until do
            element = find_element(find_element_args)
            element ? element_click(element) : nil
          end
        end

        def wait_for_element(find_element_args)
          wait.until { find_element(find_element_args) }
        end

        def wait_for_download(timeout = nil)
          initial_downloads = downloads.current
          yield
          new_downloads = []
          wait(timeout).until do
            new_downloads = downloads.current - initial_downloads
            new_downloads.any?
          end
          new_downloads.first
        end

        def wait_for_url_change(&block)
          previous_url = current_url
          block&.call

          wait.until { current_url != previous_url }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aranha-selenium-0.10.1 lib/aranha/selenium/session/wait.rb
aranha-selenium-0.10.0 lib/aranha/selenium/session/wait.rb