Reputation: 31
I'm trying to test jquery-file-upload plugin with the autoUpload option enabled using capybara/cucumber. The issue appears to be related to the autoUpload options, since uploading in the test environment works when there is no autoUpload option set. I'm uploading with the attach_file capybara method. The method triggers the change event listener, but apparently not much else. It never hits the create action for the attachment, and when I try to trigger the submit event listener manually, the params[:attachment] in the create action is empty and the attachment can't be created.
The way it's set up currently is this:
This way of uplading works whenever I try to upload a file manually, but fails in the test environment. I've tried adding a hidden submit button to the attachment form and when I press that button via capybara it triggers the create action but the params is once again empty. I'm running out of ideas about what to do, so if anybody had similar problems, I'd be grateful if they could help me out.
Here's some relevant code if that can help:
jquery-file-upload initalization and attachment form
Gems used:
Rails 3.2.12
Capybara 2.1.0
Capybara-webkit 1.0.0
Jquery-fileupload-rails 0.3.0 - also tested with 0.4.1, same results
If you need any more code or any other information, let me know, I can edit this post immediately.
Thanks!
Upvotes: 3
Views: 1151
Reputation: 6096
If anyone comes across this old question and is struggling to test jquery-fileupload with Capybara and Poltergeist (the other answer is about selenium), try upgrading PhantomJS to 2.1.0 or higher.
I was having major headaches getting it to work; turns out that the source of the problem is a known issue in PhantomJS 2.0. Upgrading to 2.1.1 fixed it.
(If you're using homebrew you can update PhantomJS by running brew update
then brew upgrade phantomjs
)
Upvotes: 0
Reputation: 321
I had similar problems, but i found that:
'\'
regardless Windows supports '/'
, on *nix - only '/'
etc) and Capybara does nothing with itI use selector finding hidden elements and set path to file with platform-specific separators:
path = File.expand_path(rel_path).gsub('/', File::ALT_SEPARATOR || File::SEPARATOR)
find(:file_field, input_id, visible: false).set(path)
In my case it works with next versions of gems:
gem "jquery-fileupload-rails", "0.4.1"
gem 'capybara', '2.2.1'
gem 'selenium-webdriver', '2.41.0'
Upvotes: 0