Module: Aranha::Selenium::Session::Wait

Defined in:
lib/aranha/selenium/session/wait.rb

Constant Summary collapse

WAIT_DEFAULT_TIMEOUT =
15

Instance Method Summary collapse

Instance Method Details

#wait(timeout = nil) ⇒ Object



11
12
13
14
# File 'lib/aranha/selenium/session/wait.rb', line 11

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

#wait_default_timeoutObject



16
17
18
# File 'lib/aranha/selenium/session/wait.rb', line 16

def wait_default_timeout
  WAIT_DEFAULT_TIMEOUT
end

#wait_for_click(find_element_args, timeout = nil, &block) ⇒ Selenium::WebDriver::Element

Deprecated.

Use element.wait_click instead.

Parameters:

  • find_element_args (Array)

    Argujments for Selenium::WebDriver::Find.find_element.

  • timeout (Integer) (defaults to: nil)

Returns:

  • (Selenium::WebDriver::Element)


24
25
26
27
# File 'lib/aranha/selenium/session/wait.rb', line 24

def wait_for_click(find_element_args, timeout = nil, &block)
  find_element_args = [find_element_args] if find_element_args.is_a?(::Hash)
  element(*find_element_args).wait_click(timeout, &block)
end

#wait_for_download(timeout = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/aranha/selenium/session/wait.rb', line 33

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

#wait_for_element(find_element_args) ⇒ Object



29
30
31
# File 'lib/aranha/selenium/session/wait.rb', line 29

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

#wait_for_url_change(&block) ⇒ Object



44
45
46
47
48
49
# File 'lib/aranha/selenium/session/wait.rb', line 44

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

  wait.until { current_url != previous_url }
end