Module: PrestaShopAutomation::GeneralHelpers

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

Instance Method Summary collapse

Instance Method Details

#click(selector) ⇒ Object



39
40
41
# File 'lib/helpers/general.rb', line 39

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



47
48
49
# File 'lib/helpers/general.rb', line 47

def expect_not_to matcher
	expect(self).not_to matcher
end

#expect_to(matcher) ⇒ Object



43
44
45
# File 'lib/helpers/general.rb', line 43

def expect_to matcher
	expect(self).to matcher
end

#get_cookies_stringObject



77
78
79
# File 'lib/helpers/general.rb', line 77

def get_cookies_string
	driver.browser.manage.all_cookies.map do |c| "#{c[:name]}=#{c[:value]}" end.join ";"
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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/helpers/general.rb', line 27

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

#standard_success_checkObject



51
52
53
# File 'lib/helpers/general.rb', line 51

def standard_success_check
	expect_to have_selector '.alert.alert-success'
end

#visit(base, rest = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/helpers/general.rb', line 55

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



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/helpers/general.rb', line 65

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