Class: HayaSelect
- Inherits:
-
Object
- Object
- HayaSelect
- Defined in:
- lib/haya_select.rb
Instance Attribute Summary collapse
-
#base_selector ⇒ Object
readonly
Returns the value of attribute base_selector.
-
#not_opened_current_selected_selector ⇒ Object
readonly
Returns the value of attribute not_opened_current_selected_selector.
-
#opened_current_selected_selector ⇒ Object
readonly
Returns the value of attribute opened_current_selected_selector.
-
#options_selector ⇒ Object
readonly
Returns the value of attribute options_selector.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(id:, scope:) ⇒ HayaSelect
constructor
A new instance of HayaSelect.
- #label ⇒ Object
- #open ⇒ Object
- #options ⇒ Object
- #search(value) ⇒ Object
- #select(label) ⇒ Object
- #select_option(label:) ⇒ Object
- #toggles ⇒ Object
- #value ⇒ Object
- #wait_for_label(expected_label) ⇒ Object
- #wait_for_options(expected_options) ⇒ Object
- #wait_for_toggles(expected_toggles) ⇒ Object
- #wait_for_value(expected_value) ⇒ Object
Constructor Details
#initialize(id:, scope:) ⇒ HayaSelect
6 7 8 9 10 11 12 |
# File 'lib/haya_select.rb', line 6 def initialize(id:, scope:) @base_selector = ".haya-select[data-id='#{id}']" @not_opened_current_selected_selector = "#{base_selector}[data-opened='false'] .haya-select-current-selected" @opened_current_selected_selector = "#{base_selector}[data-opened='true'] .haya-select-current-selected" = ".haya-select-options-container[data-id='#{id}']" @scope = scope end |
Instance Attribute Details
#base_selector ⇒ Object (readonly)
Returns the value of attribute base_selector.
2 3 4 |
# File 'lib/haya_select.rb', line 2 def base_selector @base_selector end |
#not_opened_current_selected_selector ⇒ Object (readonly)
Returns the value of attribute not_opened_current_selected_selector.
2 3 4 |
# File 'lib/haya_select.rb', line 2 def not_opened_current_selected_selector @not_opened_current_selected_selector end |
#opened_current_selected_selector ⇒ Object (readonly)
Returns the value of attribute opened_current_selected_selector.
2 3 4 |
# File 'lib/haya_select.rb', line 2 def opened_current_selected_selector @opened_current_selected_selector end |
#options_selector ⇒ Object (readonly)
Returns the value of attribute options_selector.
2 3 4 |
# File 'lib/haya_select.rb', line 2 def end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
2 3 4 |
# File 'lib/haya_select.rb', line 2 def scope @scope end |
Instance Method Details
#label ⇒ Object
14 15 16 17 18 |
# File 'lib/haya_select.rb', line 14 def label wait_for_and_find("#{base_selector} .haya-select-current-selected .current-option").text rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#open ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/haya_select.rb', line 20 def open wait_for_and_find("#{base_selector}[data-opened='false'] .haya-select-current-selected").click wait_for_selector opened_current_selected_selector wait_for_selector self rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#options ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/haya_select.rb', line 29 def wait_for_selector "#{options_selector} .haya-select-option" option_elements = all("#{options_selector} .haya-select-option") option_elements.map do |option_element| { label: option_element.text, value: option_element["data-value"] } end rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#search(value) ⇒ Object
48 49 50 51 52 |
# File 'lib/haya_select.rb', line 48 def search(value) wait_for_and_find("#{base_selector} .haya-select-search-text-input").set(value) rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#select(label) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/haya_select.rb', line 54 def select(label) open select_option(label: label) wait_for_selector not_opened_current_selected_selector wait_for_no_selector self end |
#select_option(label:) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/haya_select.rb', line 62 def select_option(label:) option = wait_for_and_find("#{options_selector} .haya-select-option", exact_text: label) raise "The '#{label}'-option is disabled" if option["data-disabled"] == "true" option.click self rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#toggles ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/haya_select.rb', line 84 def toggles all("#{base_selector} .haya-select-option-presentation").map do |element| { toggle_icon: element["data-toggle-icon"], toggle_value: element["data-toggle-value"], value: element["data-value"] } end rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#value ⇒ Object
73 74 75 76 77 |
# File 'lib/haya_select.rb', line 73 def value wait_for_and_find("#{base_selector} .haya-select-current-selected input[type='hidden']", visible: false)[:value] rescue Selenium::WebDriver::Error::StaleElementReferenceError retry end |
#wait_for_label(expected_label) ⇒ Object
79 80 81 82 |
# File 'lib/haya_select.rb', line 79 def wait_for_label(expected_label) wait_for_selector "#{base_selector} .haya-select-current-selected .current-option", exact_text: expected_label self end |
#wait_for_options(expected_options) ⇒ Object
42 43 44 45 46 |
# File 'lib/haya_select.rb', line 42 def () wait_for_expect do expect().to eq end end |
#wait_for_toggles(expected_toggles) ⇒ Object
96 97 98 99 100 |
# File 'lib/haya_select.rb', line 96 def wait_for_toggles(expected_toggles) wait_for_expect do expect(toggles).to eq expected_toggles end end |
#wait_for_value(expected_value) ⇒ Object
102 103 104 105 |
# File 'lib/haya_select.rb', line 102 def wait_for_value(expected_value) wait_for_selector "#{base_selector} .haya-select-current-selected input[type='hidden'][value='#{expected_value}']", visible: false self end |