Class: GovukRSpecHelpers::FillInGovUKTextField
- Inherits:
-
Object
- Object
- GovukRSpecHelpers::FillInGovUKTextField
- Defined in:
- lib/fill_in_govuk_text_field.rb
Instance Attribute Summary collapse
-
#hint ⇒ Object
readonly
Returns the value of attribute hint.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#with ⇒ Object
readonly
Returns the value of attribute with.
Instance Method Summary collapse
- #fill_in ⇒ Object
-
#initialize(page:, label:, hint:, with:) ⇒ FillInGovUKTextField
constructor
A new instance of FillInGovUKTextField.
Constructor Details
#initialize(page:, label:, hint:, with:) ⇒ FillInGovUKTextField
Returns a new instance of FillInGovUKTextField.
6 7 8 9 10 11 |
# File 'lib/fill_in_govuk_text_field.rb', line 6 def initialize(page:, label:, hint:, with:) @page = page @label = label @hint = hint @with = with end |
Instance Attribute Details
#hint ⇒ Object (readonly)
Returns the value of attribute hint.
4 5 6 |
# File 'lib/fill_in_govuk_text_field.rb', line 4 def hint @hint end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/fill_in_govuk_text_field.rb', line 4 def label @label end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
4 5 6 |
# File 'lib/fill_in_govuk_text_field.rb', line 4 def page @page end |
#with ⇒ Object (readonly)
Returns the value of attribute with.
4 5 6 |
# File 'lib/fill_in_govuk_text_field.rb', line 4 def with @with end |
Instance Method Details
#fill_in ⇒ Object
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 51 52 53 54 55 56 57 |
# File 'lib/fill_in_govuk_text_field.rb', line 13 def fill_in labels = page.all('label', text: label, exact_text: true, normalize_ws: true) if labels.size == 0 check_for_inexact_label_match check_for_field_name_match raise "Unable to find label with the text #{label}" end @label = labels.first check_label_has_a_for_attribute label_for = @label[:for] @inputs = page.all(id: label_for) check_label_is_associated_with_a_field check_there_is_only_1_element_with_the_associated_id @input = @inputs.first check_associated_element_is_a_form_field check_input_type_is_text aria_described_by_ids = @input["aria-describedby"].to_s.strip.split(/\s+/) @described_by_elements = [] if aria_described_by_ids.size > 0 aria_described_by_ids.each do |aria_described_by_id| check_there_is_only_one_element_with_id(aria_described_by_id) @described_by_elements << page.find(id: aria_described_by_id) end end if hint check_field_is_described_by_a_hint check_hint_matches_text_given end @input.set(with) end |