Top Level Namespace

Defined Under Namespace

Modules: Testimonium

Instance Method Summary collapse

Instance Method Details

#device_androidObject



35
36
37
# File 'lib/testimonium/help_functions.rb', line 35

def device_android
  ENV['PLATFORM'] == 'android'
end

#device_iosObject



39
40
41
# File 'lib/testimonium/help_functions.rb', line 39

def device_ios
  ENV['PLATFORM'] == 'ios'
end

#find_element_id(parameter, timeout = 2, retries = 5) ⇒ Object



31
32
33
# File 'lib/testimonium/help_functions.rb', line 31

def find_element_id(parameter, timeout = 2, retries = 5)
  find_function('id', parameter, timeout, retries)
end

#find_function(function_type, parameter, timeout_time = 2, retries = 5) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/testimonium/help_functions.rb', line 5

def find_function(function_type, parameter, timeout_time = 2, retries = 5)
  element = nil
  count = 0

  retries.times do
    sleep timeout_time
    count += 1

    begin
      element = id(parameter) if function_type.eql?('id')
      element = text(parameter) if function_type.eql?('text')
    rescue Selenium::WebDriver::Error::NoSuchElementError
    end

    logger("Found: '#{parameter}' on attempt #{count}") if element
    return element if element
  end

  logger("Failed to find: '#{function_type} = #{parameter}'. Number of attempts: #{count}")
  false
end

#find_text_ios(parameter, timeout = 2, retries = 5) ⇒ Object



27
28
29
# File 'lib/testimonium/help_functions.rb', line 27

def find_text_ios(parameter, timeout = 2, retries = 5)
  find_function('text', parameter, timeout, retries)
end

#logger(msg, severity = 'debug') ⇒ Object

Parameters:

  • msg (String)

    the log message

  • severity (String) (defaults to: 'debug')

    the severity of the message, ‘debug’ by default



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/testimonium/help_functions.rb', line 45

def logger(msg, severity = 'debug')
  logger = Logger.new($stdout)
  logger.formatter = proc { |severity, datetime, _progname, msg| "#{severity}, #{datetime}, #{msg}\n" }

  if severity.eql?('debug')
    logger.debug(msg)
  elsif severity.eql?('fatal')
    logger.fatal(msg)
  else
    logger.info(msg)
  end
end