Class: TestSteps::Handlers::ClickButton

Inherits:
Base
  • Object
show all
Defined in:
lib/functions/handlers/click_button.rb

Instance Method Summary collapse

Methods inherited from Base

#login_button, #login_check, #login_process, #mem_word_check, #open_url_process, perform, #portal_mem_word, register

Instance Method Details

#perform(step_attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/functions/handlers/click_button.rb', line 8

def perform(step_attributes)
  button = step_attributes[:testvalue]
  locate = step_attributes[:locate]

  elms = %i[button span a div link image h1 h2 h3 h4]

  found_button = elms.map do |elm|
    Browser.b.send(elm, "#{locate}": button).exists?
  end.compact

  raise 'Multiple matches' if found_button.select { |i| i }.empty?

  index = found_button.index(true)
  return unless index

  case index
  when 0
    Browser.b.button("#{locate}": button).wait_until(&:exists?).click
  when 1
    Browser.b.span("#{locate}": button).wait_until(&:exists?).click
  when 2
    Browser.b.a("#{locate}": button).wait_until(&:exists?).click
  when 3
    Browser.b.div("#{locate}": button).wait_until(&:exists?).click
  when 4
    Browser.b.link("#{locate}": button).wait_until(&:exists?).click
  when 5
    Browser.b.image("#{locate}": button).wait_until(&:exists?).click
  when 6
    Browser.b.h1("#{locate}": button).wait_until(&:exists?).click
  when 7
    Browser.b.h2("#{locate}": button).wait_until(&:exists?).click
  when 8
    Browser.b.h3("#{locate}": button).wait_until(&:exists?).click
  when 9
    Browser.b.h4("#{locate}": button).wait_until(&:exists?).click
  end
  MyLog.log.info("Button: #{button} has been selected")
  true
rescue StandardError
  MyLog.log.warn("Button: #{button} does not exist")
  false
end