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.

Download a file under sahi

Fabrice BFabrice B Members
edited November -1 in Sahi - Open Source
Hi all,

I've a new problem. When i'm using my webapplication, i can download a document (word .docx). When i clic on my link, i've a pop-up "open file with", i can open the document or save the document.

When i try the same action under Sahi browser, nothing appears.

Console Logs gives me
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: Calling downloadFile
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: http://kimv2qualite2/file.do?id=8
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: downloadURL = false
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: response.isAttachment() = false
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: contentTypeHeader = application/msword
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: downloadContentType = true
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor processHttp
INFO: Content-Disposition=attachment;filename="LE MEME-1.docx"
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor save
INFO: Downloading sahi_7eb9f33a069b404183081b10ee7a580a2e58__file.do to temp directory: D:\Program Files\InstallSahiProject\userdata\temp\do
wnload
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor downloadFile
INFO: Setting download_lastFile = file.do
22 sept. 2011 14:20:53 net.sf.sahi.RemoteRequestProcessor downloadFile
INFO: Session Id: sahi_7eb9f33a069b404183081b10ee7a580a2e58

i've a crypted document in userdata\temp\download
named => sahi_7eb9f33a069b404183081b10ee7a580a2e58__file.do
but i dont know how to use it.

maybe downloadURL = false must be on true but i dont know how to do that

What is file.do ?

I read few topics, i tried few configurations in download_urls.txt and in
download_contenttypes.txt and nothing works.

thank you for your help

Fabrice

Comments

  • Hi Fabrice B,

    Add .*MEME[-]1[.]docx.* in download_urls.txt by clicking on configure on the Dashboard.

    Save. Restart Sahi.

    Also, suppose clicking a download link throws the save as dialog. You can use this:
    assertNull(_lastDownloadedFileName()); // nothing so far
    _click(_link("download")); // click on download link
    _assertEqual("setup.exe", _lastDownloadedFileName()); // check if downloaded
    _saveDownloadedAs("c:/path/myfile.docx"); // save to another path
    _clearLastDownloadedFileName(); // clear the variable
    _assertNull(_lastDownloadedFileName()); // check to see if cleared.
    

    Check if this solves your issue.

    Regards
    Sumitra
  • Hi Sumitra, hi all,

    Sorry for the delay, i was on another task since 4 days.

    I tried to add some expressions in download_urls.txt :
    .*[.]pdf[.]docx.*
    .*file[.]do.*
    .*[.].pdf.*
    .*[.].docx.*

    but it still not works...

    To answer to your question, it's not a download link, but a call on a file, a report on office word format.
    Without of sahi proxy, i've a pop-up to choose a soft to read my file, i choose Word and i can see my report.

    I just want to do the same with sahi, see this report and be able to assert in it.

    I think my problem is on file.do : i dont understand what it is...

    How could i exploit the : download_lastFile = file.do in a script ?

    Thank you

    regards

    Fabrice
  • Hi Fabrice,

    Can you try doing _saveDownloadedAs("c:/path/myfile.docx"); in your script and check if you are able to download the file in the correct format.

    Regards
    Sumitra
  • Hi sumitra,

    Yes it' is ok,

    i've the trace in the console
    28 sept. 2011 13:52:52 net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Setting download_lastFile = file.do
    28 sept. 2011 13:52:52 net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Session Id: sahi_9f0c74f90b55d04ee90be780dea997e0ecda
    tempDownloadDir D:\Program Files\InstallSahiProject\userdata\temp\download
    tempFileName file.do
    destination E:/MyReport.docx

    And my doc is correct format MSoffice-word

    What can i do with it to assert in ?

    Thx

    Fabrice
  • Hi Fabrice,

    There is a bug in Sahi because of which the downloaded file is not in the correct format.

    You can assert the file in userdata\temp\download by using:

    _lastDownloadedFileName(); API

    For more details:

    http://sahi.co.in/w/handle-file-downloads

    Regards
    Sumitra
  • Thank you Sumitra...

    it's ok for me

    i would to assert on the content of this file but with msword format i think it is hard.

    _readFile gave to me the crypted text of course...

    Before ending end the topic, would you have an idea ?

    thx

    Fabrice
  • Hi Fabrice,

    _readFile() will help you to read all type of files.

    If you are trying to read a msword format file then it will be in a crypted format because the contents will be large enough to read by Sahi.

    Regards
    sumitra
  • Sumitra,

    yes indeed...

    did you have an idea to get only the text and in a clear readable format from a .docx ?

    thx

    Fabrice
Sign In or Register to comment.