haya_select_helpers 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/haya_select.rb +90 -6
- data/lib/haya_select_helpers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94027197c1829e876fbe519781f094cfcb7db0db47d8eba3c4f851adf1f66017
|
|
4
|
+
data.tar.gz: 211c7411bd07813f3ca1d0cac83f5c3ed1e42c367ec6e1560223b36153ebd783
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38030c78ac06ea02e773157fefe7f379b780bd20bc471f7fc425a956d8f0a2a8fd8ee981c2637b3824e05979db3279d3f146a47747cefbf36c6b3f9243415268
|
|
7
|
+
data.tar.gz: aa42a5467142a1cd4f893ce1d5f3498240f8082c576fb045e928fc00e9734cd3528894bf4d8734e349416682fc62088867c944a76b5b8eadce1ab371ee116b6e
|
data/lib/haya_select.rb
CHANGED
|
@@ -78,8 +78,8 @@ class HayaSelect
|
|
|
78
78
|
def select(label = nil, value: nil)
|
|
79
79
|
open
|
|
80
80
|
select_option(label:, value:)
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
wait_for_selected_value_or_label(label, value)
|
|
82
|
+
close_if_open
|
|
83
83
|
self
|
|
84
84
|
end
|
|
85
85
|
|
|
@@ -161,16 +161,100 @@ private
|
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
def wait_for_option(selector, label)
|
|
164
|
+
return wait_for_browser { scope.page.has_selector?(selector) } unless label
|
|
165
|
+
|
|
166
|
+
option_found = false
|
|
167
|
+
|
|
168
|
+
search_terms_for(label).each do |search_term|
|
|
169
|
+
current_options_text = options_container_text
|
|
170
|
+
search_for_option(search_term)
|
|
171
|
+
|
|
172
|
+
wait_for_browser do
|
|
173
|
+
scope.page.has_selector?(selector) || options_container_updated?(search_term, current_options_text)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
if scope.page.has_selector?(selector)
|
|
177
|
+
option_found = true
|
|
178
|
+
break
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
return if option_found
|
|
183
|
+
|
|
164
184
|
wait_for_browser do
|
|
165
185
|
scope.page.has_selector?(selector)
|
|
166
186
|
end
|
|
167
|
-
|
|
168
|
-
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def wait_for_selected_value_or_label(label, value)
|
|
190
|
+
if value
|
|
191
|
+
wait_for_value(value)
|
|
192
|
+
elsif label
|
|
193
|
+
wait_for_label(label)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def search_for_option(label)
|
|
198
|
+
return unless scope.page.has_selector?(search_input_selector)
|
|
169
199
|
|
|
170
200
|
search(label)
|
|
171
|
-
|
|
172
|
-
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def options_container_updated?(search_term, previous_text)
|
|
204
|
+
return false unless scope.page.has_selector?(no_options_selector)
|
|
205
|
+
return false unless search_input_value == search_term
|
|
206
|
+
return false if previous_text.nil?
|
|
207
|
+
|
|
208
|
+
options_container_text != previous_text
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def options_container_text
|
|
212
|
+
scope.page.find(options_selector).text
|
|
213
|
+
rescue Capybara::ElementNotFound
|
|
214
|
+
nil
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def search_input_value
|
|
218
|
+
scope.page.find(search_input_selector).value
|
|
219
|
+
rescue Capybara::ElementNotFound
|
|
220
|
+
nil
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def search_terms_for(label)
|
|
224
|
+
terms = [label]
|
|
225
|
+
terms << label.split(" (", 2).first if label.include?(" (")
|
|
226
|
+
terms.uniq
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def close_if_open
|
|
230
|
+
return if scope.page.has_no_selector?(options_selector)
|
|
231
|
+
|
|
232
|
+
close_attempts = 0
|
|
233
|
+
|
|
234
|
+
while scope.page.has_selector?(options_selector) && close_attempts < 3
|
|
235
|
+
if scope.page.has_selector?(select_container_selector)
|
|
236
|
+
wait_for_and_find(select_container_selector).click
|
|
237
|
+
else
|
|
238
|
+
wait_for_and_find("body").click
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
close_attempts += 1
|
|
173
242
|
end
|
|
243
|
+
|
|
244
|
+
wait_for_no_selector options_selector
|
|
245
|
+
wait_for_selector not_opened_current_selected_selector
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def search_input_selector
|
|
249
|
+
"#{base_selector} [data-class='search-text-input']"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def no_options_selector
|
|
253
|
+
"#{options_selector} [data-class='no-options-container']"
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def select_container_selector
|
|
257
|
+
"#{base_selector} [data-class='select-container']"
|
|
174
258
|
end
|
|
175
259
|
|
|
176
260
|
# rubocop:enable Metrics/ClassLength, Style/Documentation
|