Module: PrestaShopAutomation::GeneralHelpers

Included in:
PrestaShop
Defined in:
lib/helpers/general.rb

Instance Method Summary collapse

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 click_button_named name, options={}
  selector = "button[name='#{name}']"
  if options[: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_stringObject



89
90
91
# File 'lib/helpers/general.rb', line 89

def get_cookies_string
  driver.browser.manage.all_cookies.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 get_select_options 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
  options = Hash[all("#{select_selector} option", :visible => false).to_a.each_with_index.map do |option, i|
    [option['value'], i]
  end]
  expect(options[value]).not_to be nil
  container = find("#{select_selector} + .chosen-container")
  container.click
  within container do
    click "li[data-option-array-index='#{options[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 = get_select_options(select_selector).sample[0]
  puts "Option: #{option}"
  select_by_value select_selector, option
end

#standard_success_checkObject



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 options = {}, &block
  elapsed = 0
  dt = options[:interval] || 1
  timeout = options[:timeout] || 60
  until (ok = yield) or (elapsed > timeout)
    elapsed += sleep dt
  end
  unless ok
    throw "Timeout exceeded!"
  end
end