Module: Softwear::Lib::Spec::Select2
- Defined in:
- lib/softwear/lib/spec.rb
Instance Method Summary collapse
- #select2(value, options) ⇒ Object
- #select2_no_label(value, options = {}) ⇒ Object
- #select2_search(value, options) ⇒ Object
- #select_select2_result(value) ⇒ Object
- #set_select2_field(field, value) ⇒ Object
- #targetted_select2(value, options) ⇒ Object
- #targetted_select2_search(value, options) ⇒ Object
Instance Method Details
#select2(value, options) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/softwear/lib/spec.rb', line 68 def select2(value, ) label = find_label_by_text([:from]) within label.first(:xpath,'.//..') do [:from] = "##{find('.select2-container')['id']}" end targetted_select2(value, ) end |
#select2_no_label(value, options = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/softwear/lib/spec.rb', line 77 def select2_no_label value, ={} raise "Must pass a hash containing 'from'" if not .is_a?(Hash) or not .has_key?(:from) placeholder = [:from] # TODO: still need this? # minlength = options[:minlength] || 4 click_link placeholder select_select2_result(value) end |
#select2_search(value, options) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/softwear/lib/spec.rb', line 54 def select2_search(value, ) label = find_label_by_text([:from]) within label.first(:xpath,'.//..') do [:from] = "##{find('.select2-container')['id']}" end targetted_select2_search(value, ) end |
#select_select2_result(value) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/softwear/lib/spec.rb', line 95 def select_select2_result(value) # results are in a div appended to the end of the document within(:xpath, '//body') do page.find('div.select2-result-label', text: %r{#{Regexp.escape(value)}}i).click end end |
#set_select2_field(field, value) ⇒ Object
50 51 52 |
# File 'lib/softwear/lib/spec.rb', line 50 def set_select2_field(field, value) page.execute_script %Q{$('#{field}').select2('val', '#{value}')} end |
#targetted_select2(value, options) ⇒ Object
89 90 91 92 93 |
# File 'lib/softwear/lib/spec.rb', line 89 def targetted_select2(value, ) # find select2 element and click it find([:from]).find('a').click select_select2_result(value) end |
#targetted_select2_search(value, options) ⇒ Object
62 63 64 65 66 |
# File 'lib/softwear/lib/spec.rb', line 62 def targetted_select2_search(value, ) page.execute_script %Q{$('#{[:from]}').select2('open')} page.execute_script "$('#{[:dropdown_css]} input.select2-input').val('#{value}').trigger('keyup-change');" select_select2_result(value) end |