capybara-envjs
capybara-envjs copied to clipboard
Form serialization bug if file upload is required
There is an issue with file upload testing.
I have few fields loaded via ajax. When I use browser - everything works just fine. Using envjs there is a strange bug with upload happens.
When I upload plaintext file HTTP-headers are added to it (view uploaded file in tmp/upload.csv). When I upload image - exception raises:
.. WARNIING: [Wed Feb 02 2011 19:32:20 GMT+0200 (MSK)] {ENVJS} Exception while dispatching events: TypeError: malformed UTF-8 character sequence at offset 0
oopse TypeError: malformed UTF-8 character sequence at offset 0
@:0
([object Array],1296667940527)@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/static.js:6582
([object Object],(void 0),1296667940527)@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/static.js:6341
__dispatchEvent__([object Object],[object Object],true)@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/env.js:1836
([object Object])@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/static.js:1718
([object Object])@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/static.js:5250
()@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/static.js:6203
__dispatchEvent__([object Object],[object Object],true)@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/env.js:1811
([object Object])@/Users/dm/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/envjs-0.3.8/lib/envjs/static.js:1718
WARNIING: [Wed Feb 02 2011 19:32:20 GMT+0200 (MSK)] {ENVJS} Exception while dispatching events: TypeError: malformed UTF-8 character sequence at offset 0
F-....
(::) failed steps (::)
malformed UTF-8 character sequence at offset 0 (Johnson::Error)
./features/step_definitions/web_steps.rb:29
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:28:in `/^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/'
features/import.feature:8:in `And I press "Submit"'
Failing Scenarios:
cucumber features/import.feature:5 # Scenario: Upload image file
To reproduce it I've create simple rails app with those issues: https://github.com/daemon/envjs-bug
Any thoughts?
JS doesn't have a good way of dealing with arbitrary binary data. Strings are UTF8 and you can't stuff binary into them in general, so this is limitation of using JS to implement uploads.
I remember dealing with this for some case, base64 encoding the binary, but I don't remember the scope of what I was addressing. It maybe that for the purposes of the test, I had to encode on the client side. You could look in the capy-envjs for base64 ...