Last active
March 3, 2017 09:10
-
-
Save backpackerhh/c5b78ffed5d466ec2e4d468772057747 to your computer and use it in GitHub Desktop.
Custom helpers for integration/acceptance tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FeatureHelpers | |
# Finds a file field on the page and attach a file given its path | |
def enhanced_attach_file(path) | |
field = find('input[type=file]', visible: false) | |
page.execute_script %($("##{field[:id]}").show()) | |
attach_file field[:id], path.to_s | |
end | |
# Finds a file field on the page and attach a file given its path | |
def enhanced_attach_file(path) | |
field = find('input[type=file]', visible: false) | |
attach_file field[:id], path.to_s | |
end | |
# Fills out all required fields to add a new attachment | |
def fill_out_attachment(options) | |
attachment = options.fetch(:attachment).with_indifferent_access | |
enhanced_attach_file attachment[:file].path | |
fill_in 'attachment_pixel_tracking', with: attachment[:pixel_tracking] if attachment[:pixel_tracking] | |
fill_in 'attachment_click_url', with: attachment[:click_url] if attachment[:click_url] | |
select attachment[:creative_step], from: 'attachment_creative_step_id' if attachment[:creative_step] | |
click_on_submit_button | |
end | |
# Finds last element containing given id and set given value | |
def fill_in_last_containing(id, with:) | |
find(:xpath, "(//*[contains(@id, '#{id}')])[last()]").set with | |
end | |
# Checks for presence of an image with given location | |
def have_image(src) | |
have_xpath("//img[@src='#{src}']") | |
end | |
# Checks for presence of a link containing given text and URL | |
def have_link_containing(text, href:) | |
have_xpath "//a[contains(text(), '#{text}') and contains(@href, '#{href}')]" | |
end | |
# Selects an option from a selector provided by Chosen, the JS library | |
def select_from_chosen(item_text, options) | |
field = find_field(options[:from], visible: false) | |
find("##{field[:id]}_chosen").click | |
find("##{field[:id]}_chosen ul.chosen-results li", text: item_text).click | |
end | |
# Marks attachment to be destroyed when form is submitted | |
def mark_attachment_for_destruction(position: 0) | |
find("input#creative_attachments_attributes_#{position}__destroy[type=checkbox]").set(true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment