Class: GovukRSpecHelpers::ClickButton

Inherits:
Object
  • Object
show all
Defined in:
lib/click_govuk_button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, button_text:, disabled: false) ⇒ ClickButton

Returns a new instance of ClickButton.



6
7
8
9
10
# File 'lib/click_govuk_button.rb', line 6

def initialize(page:, button_text:, disabled: false)
  @page = page
  @button_text = button_text
  @disabled = disabled
end

Instance Attribute Details

#button_textObject (readonly)

Returns the value of attribute button_text.



4
5
6
# File 'lib/click_govuk_button.rb', line 4

def button_text
  @button_text
end

#disabledObject (readonly)

Returns the value of attribute disabled.



4
5
6
# File 'lib/click_govuk_button.rb', line 4

def disabled
  @disabled
end

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/click_govuk_button.rb', line 4

def page
  @page
end

Instance Method Details

#clickObject



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
# File 'lib/click_govuk_button.rb', line 12

def click
  @buttons = page.all('button', text: button_text, exact_text: true)

  if @buttons.empty?
    @buttons = page.all('a.govuk-button', text: button_text, exact_text: true)
  end

  if @buttons.empty?
    @buttons = page.all("input[type=submit][value=\"#{Capybara::Selector::CSS.escape(button_text)}\"]")
  end

  if @buttons.size == 0
    check_for_inexact_match
    raise "Unable to find button \"#{button_text}\""
  end

  check_that_button_text_is_unique_on_the_page

  @button = @buttons.first

  check_data_module_attribute_is_present
  check_role_is_present_if_button_is_a_link
  check_button_is_not_draggable_if_button_is_a_link
  check_if_button_is_disabled
  check_for_govuk_class

  @button.click unless disabled
end