Just a quick one today: when you struggle with writing Acceptance Tests for file uploads using PhantomJS (will version 2.5 ever come out? *sigh*), here are two possible solutions for you.
File inputs are ugly, let’s just not show them
In my case, the input field was hidden by using a very low opacity value, so I set it to 1 just before attaching the actual file:
// PhantomJS 2.1 workaround #1:
// Make input[type=file] visible
If this solves your problem – great! If not, I got one more.
Don’t rush – one at a time
While the first issue is somewhat understandable … well, maybe …, anyway, I found the second one just by good old trial-and-error: PhantomJS doesn’t like multiple uploads!
Now we don’t want to remove the possibility to upload multiple files just to please PhantomJS, so let’s do another tweak:
// Phantomjs 2.1 workaround #2:
// Don’t use multiple uploads
Of course we can’t test multiple uploads that way, which is a bit sad, but right now I’m afraid we have to live with that.
Did it blend?
If you found these two little tips helpful, or if you have another nasty PhantomJS workaround at hand, please drop a comment below!