Top Level Namespace

Defined Under Namespace

Modules: WebDriverUtils

Instance Method Summary collapse

Instance Method Details

#ignore(&block) ⇒ Object

Return block.call and ignore any exceptions.



122
123
124
125
# File 'lib/webdriver_utils/wait.rb', line 122

def ignore(&block)
  block.call
rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException
end

#jenkins?Boolean

Returns true if env is set and not empty Returns false if env is not set or empty.

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/webdriver_utils/sauce.rb', line 25

def jenkins?
  env = ENV['JENKINS_SERVER_COOKIE']
  env && !env.empty?
end

#sauce?Boolean

Returns true if both sauce user and sauce key are defined. Returns false if they're not defined.

Returns:

  • (Boolean)


19
20
21
# File 'lib/webdriver_utils/sauce.rb', line 19

def sauce?
  !!(sauce_user && sauce_key)
end

#sauce_keyObject

Returns sauce key if env is set and not empty. If env isn't defined then nil is returned.



12
13
14
15
# File 'lib/webdriver_utils/sauce.rb', line 12

def sauce_key
  env = ENV['SAUCE_ACCESS_KEY']
  (env && !env.empty?) ? env : nil
end

#sauce_userObject

Returns sauce username if env is set and not empty. If env isn't defined then nil is returned.



5
6
7
8
# File 'lib/webdriver_utils/sauce.rb', line 5

def sauce_user
  env = ENV['SAUCE_USERNAME']
  (env && !env.empty?) ? env : nil
end

#wait(opts = {}, &block) ⇒ Object

Check every interval seconds to see if block.call doesn't raise an exception. Give up after timeout seconds.

Wait code from the selenium Ruby gem https://github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb

If only a number is provided then it's treated as the timeout value.

Parameters:

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • :timeout (Numeric) — default: 30

    Seconds to wait before timing out.

  • :interval (Numeric) — default: 0.5

    Seconds to sleep between polls.

  • :message (String)

    Exception message if timed out.

  • :ignore (Array, Exception)

    Exceptions to ignore while polling (default: Exception)



116
117
118
119
# File 'lib/webdriver_utils/wait.rb', line 116

def wait(opts = {}, &block)
  opts = WebDriverUtils._process_wait_opts(opts).merge(return_if_true: false)
  WebDriverUtils._generic_wait opts, &block
end

#wait_true(opts = {}, &block) ⇒ Object

Check every interval seconds to see if block.call returns a truthy value. Note this isn't a strict boolean true, any truthy value is accepted. false and nil are considered failures. Give up after timeout seconds.

Wait code from the selenium Ruby gem https://github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb

If only a number is provided then it's treated as the timeout value.

Parameters:

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • :timeout (Numeric) — default: 30

    Seconds to wait before timing out.

  • :interval (Numeric) — default: 0.5

    Seconds to sleep between polls.

  • :message (String)

    Exception message if timed out.

  • :ignore (Array, Exception)

    Exceptions to ignore while polling (default: Exception)



98
99
100
101
# File 'lib/webdriver_utils/wait.rb', line 98

def wait_true(opts = {}, &block)
  opts = WebDriverUtils._process_wait_opts(opts).merge(return_if_true: true)
  WebDriverUtils._generic_wait opts, &block
end