Top Rounds
| We are Hiring! |
[Hide Navigation]

Handle File Downloads ·

Sahi’s proxy detects file downloads, and automatically saves them to sahi/userdata/temp/download directory. Sahi also adds the sessionId to the file name, so that multiple simultaneous tests do not overwrite each others files.

So if you were clicking on a “download” link which downloads a “setup.exe” file, this is how Sahi will handle it.

1) Click on “download” link
2) Sahi detects that it is a downloadable file, based on its MimeType and Content-Disposition headers. It then downloads and saves the file into sahi/userdata/temp/download/ after renaming it to something like: sahi_0384a26207e6104f5f08868032bd170de76d__setup.exe
3) Once the file is downloaded Sahi exposes the original name of the file (“setup.exe”) through the API: _lastDownloadedFileName()
4) Another API, _saveDownloadedAs, allows the file to be renamed and copied over to a convenient directory for you to work on.
5) API: _clearLastDownloadedFileName clears out the _lastDownloadedFileName() so that further files can be downloaded and worked upon.

Example:

_assertNull(_lastDownloadedFileName()); // nothing so far _click(_link("download")); // click on download link _assertEqual("setup.exe", _lastDownloadedFileName()); // check if downloaded _saveDownloadedAs("c:/path/myfile.txt"); // save to another path _clearLastDownloadedFileName(); // clear the variable _assertNull(_lastDownloadedFileName()); // check to see if cleared.

More information:
Sahi detects that a file is to be downloaded, based on

  1. its content type (configurable via sahi/userdata/config/download_contenttypes.txt)
  2. The Content-Disposition: attachment header
  3. Whether the URL is configured in sahi/userdata/config/download_urls.txt

If you see a file download dialog during playback, do the following:

1) Check if the download URL follows a specific pattern. If yes, add the pattern of the URL to download_urls.txt
Eg., if your download url is
http://mysite.example.com/export_doc.jsp?id=12318812 ,
add
.export_doc[.]jsp.
to download_urls.txt

2) If there are multiple files that are to be downloaded, and they all are of a particular content-type, add the content type to download_contenttypes.txt

3) If your file download response always has content-disposition as “attachment”, you can tell sahi to download them by default by setting
download.download_if_contentdisposition_is_attachment=true
in sahi/userdata/config/userdata.properties




---


Top Rounds