module PrestaShopAutomation::GeneralHelpers

Public Instance Methods

click(selector) click to toggle source
# File lib/helpers/general.rb, line 51
def click selector
        find(selector).click
end
click_button_named(name, options={}) click to toggle source
# 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) click to toggle source
# File lib/helpers/general.rb, line 8
def click_label_for id
        find("label[for='#{id}']").click
end
expect_not_to(matcher) click to toggle source
# File lib/helpers/general.rb, line 59
def expect_not_to matcher
        expect(self).not_to matcher
end
expect_to(matcher) click to toggle source
# File lib/helpers/general.rb, line 55
def expect_to matcher
        expect(self).to matcher
end
get_cookies_string() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/helpers/general.rb, line 4
def onoff val
        val ? 'on' : 'off'
end
select_by_value(select_selector, value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_check() click to toggle source
# File lib/helpers/general.rb, line 63
def standard_success_check
        expect_to have_selector '.alert.alert-success'
end
version_gte(v) click to toggle source
# 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) click to toggle source
Calls superclass method
# 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 = {}) click to toggle source
# 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