Last active
December 20, 2015 19:19
-
-
Save DylanLacey/6182249 to your computer and use it in GitHub Desktop.
Using setFileDetector from Cucumber with Capybara
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
Given /^I upload (\w+)$/ do |filepath| | |
# page.driver.browser gives you the Selenium object | |
selenium = page.driver.browser | |
selenium.file_detector = lambda do |args| | |
# Capybara checks the file exists so we can just return the first argument, the file path | |
args.first.to_s | |
end | |
# Scope to a specific form | |
within("#form") do | |
# file_input_locator can be a name, id or label of the file field | |
attach_file ("file_input_locator", filepath) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment