{"record":{"id":"e99adfbd0763a54d","repo":"teamcapybara/capybara","slug":"you-may-only-upload-files-local-file-inspect","errorCode":null,"errorMessage":"You may only upload files: #{local_file.inspect}","messagePattern":"You may only upload files: #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/selenium/nodes/firefox_node.rb","lineNumber":127,"sourceCode":"    when String\n      # https://bugzilla.mozilla.org/show_bug.cgi?id=1405370\n      keys = keys.upcase if (browser_version < 64.0) && down_keys&.include?(:shift)\n      actions.send_keys(keys)\n    when Symbol\n      actions.send_keys(keys)\n    when Array\n      down_keys.push\n      keys.each { |sub_keys| _send_keys(sub_keys, actions, down_keys) }\n      down_keys.pop.reverse_each { |key| actions.key_up(key) }\n    else\n      raise ArgumentError, 'Unknown keys type'\n    end\n    actions\n  end\n\n  def upload(local_file)\n    return nil unless local_file\n    raise ArgumentError, \"You may only upload files: #{local_file.inspect}\" unless File.file?(local_file)\n\n    file = ::Selenium::WebDriver::Zipper.zip_file(local_file)\n    bridge.http.call(:post, \"session/#{bridge.session_id}/file\", file: file)['value']\n  end\n\n  def browser_version\n    driver.browser.capabilities[:browser_version].to_f\n  end\nend\n","sourceCodeStart":109,"sourceCodeEnd":137,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/selenium/nodes/firefox_node.rb#L109-L137","documentation":"Raised by the Selenium Firefox node when #attach_file (setting a file input) is given a path that is not an existing regular file (File.file? returns false). Firefox/geckodriver cannot set files directly on the input the way Chrome can, so Capybara zips the local file and POSTs it to geckodriver's session/:session_id/file endpoint, which requires a real on-disk file. The message echoes the inspected path that failed the check.","triggerScenarios":"Calling page.attach_file('Resume', 'spec/fixtures/files/missing.pdf') (or any #set on a file field) under the Selenium Firefox driver where the path does not exist, points to a directory, or is relative and does not resolve from the process working directory (Dir.pwd differs between rspec, rake, spring, and IDE runners).","commonSituations":"Specs run from a different working directory breaking relative fixture paths; typo'd fixture filenames; attaching before a generated file is written/closed; passing a directory instead of a file; CI checkout layout differing from local.","solutions":["Verify the path before attaching: raise \"fixture missing: #{path}\" unless File.file?(path)","Build absolute paths from a known root: Rails.root.join('spec/fixtures/files/doc.pdf') or File.expand_path('...', __dir__)","If the file is generated at runtime, make sure the write completes (file closed/flushed) before attach_file","Print Dir.pwd in the failing spec to catch working-directory drift between local and CI runners"],"exampleFix":"# before\npage.attach_file('Resume', 'spec/fixtures/files/resume.pdf')\n\n# after\npath = File.expand_path('spec/fixtures/files/resume.pdf', __dir__)\nraise \"fixture missing: #{path}\" unless File.file?(path)\npage.attach_file('Resume', path)","handlingStrategy":"validation","validationCode":"def uploadable?(path)\n  path.is_a?(String) && File.file?(path)\nend\n\npage.attach_file('Resume', path) if uploadable?(path)","typeGuard":"def assert_uploadable_file!(path)\n  return path if path.is_a?(String) && File.file?(path)\n  raise ArgumentError, \"not an existing file: #{path.inspect}\"\nend\n\npage.attach_file('Resume', assert_uploadable_file!(path))","tryCatchPattern":"begin\n  page.attach_file('Resume', path)\nrescue ArgumentError => e\n  raise \"fixture problem (pwd=#{Dir.pwd}): #{e.message}\"\nend","preventionTips":["Build fixture paths with Rails.root.join or File.expand_path(__dir__), never bare relative paths","Add a suite-wide existence check for fixture files in spec_helper","Write generated upload artifacts to Dir.mktmpdir and clean up in an ensure block"],"tags":["file-upload","attach-file","firefox","selenium","file-path"],"backgroundTag":"file-not-found","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}