Module: PrestaShopAutomation::GeneralHelpers
- Included in:
- PrestaShop
- Defined in:
- lib/helpers/general.rb
Instance Method Summary collapse
- #click(selector) ⇒ Object
- #click_button_named(name, options = {}) ⇒ Object
- #click_label_for(id) ⇒ Object
- #expect_not_to(matcher) ⇒ Object
- #expect_to(matcher) ⇒ Object
- #get_cookies_string ⇒ Object
- #get_select_options(select_selector) ⇒ Object
- #onoff(val) ⇒ Object
- #select_by_value(select_selector, value) ⇒ Object
- #select_by_value_jqChosen(select_selector, value) ⇒ Object
- #select_random_option(select_selector) ⇒ Object
- #standard_success_check ⇒ Object
- #version_gte(v) ⇒ Object
- #visit(base, rest = nil) ⇒ Object
- #wait_until(options = {}, &block) ⇒ Object
Instance Method Details
#click(selector) ⇒ Object
51 52 53 |
# File 'lib/helpers/general.rb', line 51 def click selector find(selector).click end |
#click_button_named(name, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/helpers/general.rb', line 12 def name, ={} selector = "button[name='#{name}']" if [:first] first(selector).click else find(selector).click end end |
#click_label_for(id) ⇒ Object
8 9 10 |
# File 'lib/helpers/general.rb', line 8 def click_label_for id find("label[for='#{id}']").click end |
#expect_not_to(matcher) ⇒ Object
59 60 61 |
# File 'lib/helpers/general.rb', line 59 def expect_not_to matcher expect(self).not_to matcher end |
#expect_to(matcher) ⇒ Object
55 56 57 |
# File 'lib/helpers/general.rb', line 55 def expect_to matcher expect(self).to matcher end |
#get_cookies_string ⇒ Object
89 90 91 |
# File 'lib/helpers/general.rb', line 89 def driver.browser.manage..map do |c| "#{c[:name]}=#{c[:value]}" end.join ";" end |
#get_select_options(select_selector) ⇒ Object
27 28 29 30 31 |
# File 'lib/helpers/general.rb', line 27 def select_selector all("#{select_selector} option", :visible => false).to_a.map do |option| [option[:value], option.text] end end |
#onoff(val) ⇒ Object
4 5 6 |
# File 'lib/helpers/general.rb', line 4 def onoff val val ? 'on' : 'off' end |
#select_by_value(select_selector, value) ⇒ Object
21 22 23 24 25 |
# File 'lib/helpers/general.rb', line 21 def select_by_value select_selector, value within select_selector do find("option[value='#{value}']").click end end |
#select_by_value_jqChosen(select_selector, value) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/helpers/general.rb', line 39 def select_by_value_jqChosen select_selector, value = Hash[all("#{select_selector} option", :visible => false).to_a.each_with_index.map do |option, i| [option['value'], i] end] expect([value]).not_to be nil container = find("#{select_selector} + .chosen-container") container.click within container do click "li[data-option-array-index='#{[value]}']" end end |
#select_random_option(select_selector) ⇒ Object
33 34 35 36 37 |
# File 'lib/helpers/general.rb', line 33 def select_random_option select_selector option = (select_selector).sample[0] puts "Option: #{option}" select_by_value select_selector, option end |
#standard_success_check ⇒ Object
63 64 65 |
# File 'lib/helpers/general.rb', line 63 def standard_success_check expect_to have_selector '.alert.alert-success' end |
#version_gte(v) ⇒ Object
93 94 95 |
# File 'lib/helpers/general.rb', line 93 def version_gte v Gem::Version.new(@version.dup) >= Gem::Version.new(v.dup) end |
#visit(base, rest = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/helpers/general.rb', line 67 def visit base, rest=nil url = if rest == nil base else base.sub(/\/\s*$/, '') + '/' + rest.sub(/^\s*\//, '') end super url end |
#wait_until(options = {}, &block) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/helpers/general.rb', line 77 def wait_until = {}, &block elapsed = 0 dt = [:interval] || 1 timeout = [:timeout] || 60 until (ok = yield) or (elapsed > timeout) elapsed += sleep dt end unless ok throw "Timeout exceeded!" end end |