intern

How do I test file download using intern framework?


I have a requirement where I need to write a functional test for downloading a file and testing its contents. There are two parts:

  1. Ensure clicking on a link downloads a file.
  2. Reading the file and checking its contents.

It's a csv file, so I can possibly do some manipulation with the content.


Solution

  • There are several issues with doing this. One is that if you're running a browser on a remote system, you'll need a way to get the file back to the system running Intern. The second issue is that you'll need to know where the downloaded file ended up when it was downloaded. A third issue is that some browsers (FF and IE) pop open OS-level dialogs that Selenium can't deal with.

    The first question is: do you really need to download a file in the browser? It sounds like you may be testing a service rather than the browser, in which case you may be able to just download the file using Intern and inspect it there.

    Assuming you do need to download a file via the browser, you should be able to configure a browser to not open a confirm dialog and to download the file to a known location, which at least handles 2 of the 3 issues mentioned above. Note that I haven't actually tested this.

    In Firefox you can setup a test profile and use it when running tests. You'll likely need to configure the following properties:

    For Chrome you'll pass options through the environment descriptor. The specific options should be:

    Once you've setup the browser, your test code would need to click the link, then wait for some indeterminate amount of time (Selenium doesn't provide any sort of download progress data), then grab the file from the Intern test itself (using a network request or local file operation) to inspect it.