Acceptance test for file uploading


I’d like to create a basic acceptance test in ember that uploads a file. I can mock the server with Pretender, but I need to know how to fill the input type="file" field with a file from my filesystem. So the questions are basically:

  1. How to fill the input file field with ember test helpers, do I use fillIn helper?
  2. How to add sample files to a folder and get them from my acceptance test. Is it possible to get the current path of my Ember project from the acceptance test to select a file from the filesystem to be uploaded? In Rails we use to use Rails.root for this purpose.


Has anyone found a solution for this problem? I have a required file upload field, and no idea how I can fill this in in my acceptance tests.


It depends on how you’re uploading it. If you’re using XHR2 to upload the file, you can test most of it.

What we’ve done is creating a stubbed out HTML5 Blob on one end, and using mockjax on the other end. But what you can’t do is actually click the upload button. So on the front end, you trigger a fake change event for the input[type=file] element and send it the fake HTML5 Blob. Then you go through the normal process (filling our fields and click submit). Lastly you’ll use mockjax to inspect the blob that’s uploaded.


In the end, I ended up with adapting my file upload component to include text fields in test environment. I use ember-plupload, and extended to file upload component. Basically, I check if the current environment is test, and if it is, I add two text fields (filename & filesize) as well as a button to the component. When clicking the button, I just call the regular upload action. This works quite well so far.