Skip to content

Instantly share code, notes, and snippets.

@DylanLacey
Last active December 20, 2015 19:19
Show Gist options
  • Save DylanLacey/6182249 to your computer and use it in GitHub Desktop.
Save DylanLacey/6182249 to your computer and use it in GitHub Desktop.
Using setFileDetector from Cucumber with Capybara
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