18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Automatical download doesn't work if file is opened from a link

wgoriswgoris Members
edited February 2011 in Sahi - Open Source
Hello,

I cannot download (save) a file when it is present on the screen as a link.

Example of the html code is: <a href="#" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('opladenForm'),'opladenForm:bijlagenTable:29:j_id41,opladenForm:bijlagenTable:29:j_id41','');}return false">test.pdf</a>

If I click on this link in my sahi script, the popup 'Opening test.pdf' appears. I have the following lines in the .../apps/sahi/userdata/config/download_contenttypes.txt :

zip
excel
doc
application/vnd.ms
application/ms
application/octet-stream
text/plain
application/pdf
application/x-pdf
application/acrobat
applications/vnd.pdf
text/pdf
text/x-pdf

If I want to download a pdf file by clicking on a button that's on the same screen, the sahi automatical download function works! (Example: <input type="submit" value="Document" name="identificatieForm:j_id88"> => the *.pdf file is automatically downloaded by sahi).

I think this means my config is correct, but that there is a problem in sahi when a file download is started from a link? I use sahi v3.5 on Ubuntu 10.04 with firefox 3.6.13.

Can someone help me with this please?

Thank you in advance.

Comments

  • narayannarayan Administrators
    Hi wgoris,

    It is possible that the two links return different content-types and so, only one of them works.

    Try this.
    1) With the Sahi proxy on, navigate to the screen where you have the download link.
    2) Stop the proxy (Leave the browser open)
    3) Open sahi/config/sahi.properties and change
    debug.traffic.log.unmodified=false
    to
    debug.traffic.log.unmodified=true
    4) Restart Sahi.
    5) Click on the download link.
    6) Once the pdf appears, stop the proxy, and change back to
    debug.traffic.log.unmodified=false
    (Otherwise the log folder will quickly fill your harddisk)
    7) Open sahi/userdata/log/traffic/ directory
    8) There must be a few folders created. Look for the one which best resembles your download link URL, and look at response.header_unmodified.txt
    9) Check for the Content-Type header and see whether it is different from the ones you have in download_contenttypes.txt. If not present, add it, restart Sahi, and check.

    Let us know what you find.

    Regards,
    Narayan
  • Hello narayan,

    This is what I found in the logging:

    POST http://192.168.101.200:8080/imjv-eloket/secured/swf/identificatie-aangifte-flow?execution=e17s36 HTTP/1.1
    Host: 192.168.101.200:8080
    User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 115
    Proxy-Connection: keep-alive
    Referer: http://192.168.101.200:8080/imjv-eloket/secured/swf/identificatie-aangifte-flow?execution=e17s36
    Cookie: JSESSIONID=54CD1C6241619EC8D4A5324C6351C703; sahisid=sahi_f39353190b18604c3d09e950adcdc2cfb60a
    Content-Type: multipart/form-data; boundary=

    53755098418417857661281339740
    Content-Length: 680

    I added the line multipart/form-data to the download_contenttypes.txt file, but the problem still exists.

    Best regards,
    Werner Goris
  • narayannarayan Administrators
    Hey I am sorry, it should be

    response.header_unmodified.txt
    not
    request.header_unmodified.txt

    I am updating the above post to reflect that.

    Regards,
    Narayan
  • Hi,

    There is no Content-Type header defined in the generated response.header_unmodified.txt file.

    Server: Apache-Coyote/1.1
    Pragma: public
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    Cache-Control: public
    Content-Disposition: attachment;filename=test_pdf_document.pdf
    X-Powered-By: JSF/1.2
    X-Powered-By: JSF/1.2
    X-Powered-By: JSF/1.2
    Date: Thu, 24 Feb 2011 10:43:10 GMT
    Content-Length: 18650
  • narayannarayan Administrators
    That looks correct.

    Please open sahi/config/userdata.properties,
    and add

    download.download_if_contentdisposition_is_attachment=true

    at the end of it.

    Restart Sahi, and check if it works.

    Regards,
    Narayan
  • Hello,

    It works after I added the line. Thank a lot!
This discussion has been closed.