I encounter a scenario where the browser opens up a window on the computer to attach a file.  I am delighted to find the “attach_file” function.

Below is the code:

Then /^I attach file “([^”]*)” into “([^”]*)”$/ do |filename, id|
filepath=File.expand_path(Dir.pwd)+”/features/support/”+filename
attach_file(id,filepath)
find(:xpath,”//button[@id=’file-submit-button’]”).click
sleep 5
end