Class: Taf::TestSteps::Handlers::ClickButton

Inherits:
Base
  • Object
show all
Defined in:
lib/taf/test_steps/handlers/base/click_button.rb

Overview

Click Button function.

Instance Method Summary collapse

Methods inherited from Base

#initialize, #login_check, #login_process, perform, #portal_mem_word, register, #url_check

Constructor Details

This class inherits a constructor from Taf::TestSteps::Handlers::Base

Instance Method Details

#performObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/taf/test_steps/handlers/base/click_button.rb', line 10

def perform
  # Optimisation: if we can immediately find the target in the DOM
  # under a specific tag we should use it.
  @tag = %i[button span a div link image h1 h2 h3 h4].find do |e|
    Taf::Browser.b.send(e, "#{@locate}": @value).exists?
  end

  # Otherwise, fallback to locating across the entire DOM.
  # This can be necessary for when content rendering is deferred
  # (e.g., a loader in a SPA) or if the user wants to use CSS or XPath.
  @tag ||= :element

  Taf::Browser.b.send(@tag, "#{@locate}": @value).wait_until(&:exists?)
              .click

  Taf::MyLog.log.info("Button: #{@value} has been selected")
  true
rescue StandardError
  Taf::MyLog.log.warn("Button: #{@value} does not exist")
  false
end