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.

lastDownloadedFileName is null though file is downloaded

smitty1_2smitty1_2 Members
edited August 2011 in Sahi - Open Source
OS: Windows 7, 64bit.
Browser: Firefox 3.6, Safari 5.1, Internet Explorer 8.
Sahi Build: 2011-07-19.

I download a .jsp file. Download itself works fine. Filename looks like this:

sahi_d7324d6f02ff6041960a4ec02ca782fa0b08__ExcelViewerDetail.jsp

But _lastDownloadedFileName is null no matter what browser I use. I added jsp to download_contenttypes.txt. I added ".ExcelViewerDetail[.]jsp." to download_urls.txt. And I added download.download_if_contentdisposition_is_attachment=true to userdata.properties but none of this helped.

Sahi console log says this:

INFO: Downloading sahi_a49b70a10518b04d770bb5307acf0b8239e4__ExcelViewerDetail.jsp to temp directory: C:\Users\Yannick\sahi_v35_0719\userdata\temp\download
Aug 9, 2011 3:04:14 PM net.sf.sahi.RemoteRequestProcessor downloadFile
INFO: Setting download_lastFile = ExcelViewerDetail.jsp
Aug 9, 2011 3:04:14 PM net.sf.sahi.RemoteRequestProcessor downloadFile
INFO: Session Id: sahi_a49b70a10518b04d770bb5307acf0b8239e4
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: Calling downloadFile
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: https://httptunnel.net/webapp/Term/jsp/ExcelViewerDetail.jsp?id=0.10035331
769272926
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: downloadURL = false
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: response.isAttachment() = false
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: contentTypeHeader = application/vnd.ms-excel
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: downloadContentType = true
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor processHttp
INFO: Content-Disposition=null
Aug 9, 2011 3:07:00 PM net.sf.sahi.RemoteRequestProcessor save

It even says "download_lastFile = ExcelViewerDetail.jsp" but in the code I get null. The code looks like this:
_assertNull(_lastDownloadedFileName());
_click(_submit(" OK ")); //click on download link
_assertEqual("ExcelViewerDetail.jsp", _lastDownloadedFileName()); //check if downloaded
_saveDownloadedAs($filepath + $currentContract + "_downloaded.csv");

I appreciate any help on this.

Regards

Comments

  • TheeranTheeran Members
    edited August 2011
    Hi smitty1_2,

    Try the following steps,

    Change the .ExcelViewerDetail[.]jsp to .*ExcelViewerDetail[.]jsp. Remove jsp to download_contenttypes.txt.Modify download.download_if_contentdisposition_is_attachment to false from userdata.properties since the content.disposition is not attachment.Try with _lastDownloadedFileName API.
    It should return the name of the jsp file downloaded.
    Is your application downloading Excel file or jsp page?

    Regards,
    Theeran.
  • Hi Theeran,

    Thank you for your suggestions. Unfortunately they didn't help. I am downloading a jsp file but the content can be viewed in Excel. When you download the file without Sahi you get a popup which suggests to open the file in Excel. When Excel opens you get the message:"The file you are trying to open is in a different file format than specified by the file extension. Do you really want to open etc". When you then click Yes the file opens fine.

    Here is more of the console output. This time in the right order. Note the changes in bold font:

    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: Calling downloadFile
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: https://httptunnel.net/webapp/Term/jsp/ExcelViewerDetail.jsp?id=0.52226729
    22541839
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: downloadURL = true
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: response.isAttachment() = false
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: contentTypeHeader = application/vnd.ms-excel
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: downloadContentType = true
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: Content-Disposition=null
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor save
    INFO: Downloading sahi_baeb10ac07a45047a30ae9a0fa3eceda9546__ExcelViewerDetail.j
    sp to temp directory: C:\Users\Yannick\sahi_v35_0719\userdata\temp\download
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Setting download_lastFile = ExcelViewerDetail.jsp
    Aug 10, 2011 11:40:31 AM net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Session Id: sahi_baeb10ac07a45047a30ae9a0fa3eceda9546
    tempDownloadDir C:\Users\Yannick\sahi_v35_0719\userdata\temp\download
    tempFileName null
    destination C:\Users\Yannick\sahiCSV\Mallory\Mallory_downloaded\C0332_downloaded
    .csv
    java.io.FileNotFoundException: C:\Users\Yannick\sahi_v35_0719\userdata\temp\down
    load\sahi_a87b3c4308834047380899b0f7270e2bd57f__null (The system cannot find the
    file specified)

    ...
  • smitty1_2,

    You might be trying to download the wrong file here. You should be downloading the excel file instead.

    To download this,
    Add the path to the excel file that will be downloaded in download_url.txt.
    Eg: If ExcelViewerDetail.jsp generates a file called data.xls,
    add, .*data[.]xls
    Save and restart Sahi

    Alternately, you can also add this to download_contenttypes.txt
    application/vnd.ms-excel
    Save and restart Sahi

    Regards,
    _dkulkarni
  • smitty1_2smitty1_2 Members
    edited August 2011
    Hi _dkulkarni,

    ExcelViewerDetail.jsp does not generate a xls file as you can see in log:

    INFO: Downloading sahi_baeb10ac07a45047a30ae9a0fa3eceda9546__ExcelViewerDetail.j
    sp
    to temp directory: C:\Users\Yannick\sahi_v35_0719\userdata\temp\download

    The file appears exactly with that filename from the log in the temp folder. Same when I do it without Sahi. The popup window says: "Do you awant to download ExcelViewerDetail.jsp?". That's why I don't understand that the filename doesn't appear in the code.


    Edit: I guess the Content-Disposition which is null could be the problem.

    response.header_modified.txt says:

    HTTP/1.1 204 No Content
    Cache-Control: no-cache
    Pragma: no-cache
    Expires: 0
    Accept-Ranges: none
    Proxy-Connection: close
    Content-Length: 0


    unmodified says:

    Date: Tue, 09 Aug 2011 20:53:52 GMT
    Server: WebSphere Application Server/6.1
    Keep-Alive: timeout=300, max=99
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: application/vnd.ms-excel
    Content-Language: en-US
    Content-Length: 49299
  • Hi smitty1_2,

    Can you please check if .jsp file is present in download by navigating to <Sahi-home>/userdata/temp/download.

    Regards
    Sumitra
  • smitty1_2 wrote:

    INFO: Downloading sahi_baeb10ac07a45047a30ae9a0fa3eceda9546__ExcelViewerDetail.j
    sp
    to temp directory: C:\Users\Yannick\sahi_v35_0719\userdata\temp\download

    The file appears exactly with that filename from the log in the temp folder.
  • tcnhtcnh Members
    I'm experiencing something similar. A javascript calls a 1x1px image in our application to keep statistics. Is there any progress on this?

    userdata\config\download_urls.txt contains a pattern to download the gifs and in the console, I see the file being downloaded. The file is written to temp\download as well.

    _lastDownloadedFileName() however, stays null.

    Console:
    INFO: Calling downloadFile
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: hxxp://xxxx.domain.nl/stats-trigger.gif?js=1&ts=1327582581311
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: downloadURL = true
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: response.isAttachment() = false
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: contentTypeHeader = image/gif
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: downloadContentType = false
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor processHttp
    INFO: Content-Disposition=null
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor save
    INFO: Downloading sahi_91f1051901b65046c00ac3b01db52c4d5ebc__stats-trigger.gif t
    o temp directory: C:\APPS\sahi\userdata\temp\download
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Setting download_lastFile = stats-trigger.gif
    26-jan-2012 13:56:56 net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Session Id: sahi_91f1051901b65046c00ac3b01db52c4d5ebc
    26-jan-2012 13:56:57 net.sf.sahi.RemoteRequestProcessor processHttp
  • Hi tcnh,

    Could you please post how you have included gifs in <sahi-home>\userdata\config\download_urls.txt to be downloaded.

    Regards
    Sumitra
  • tcnhtcnh Members
    Hi Sumitra,

    It's a white-pixel call for stats gathering. download-urls.txt contains .*stats-trigger[.]gif.*
    I see the file being downloaded in the console logging (see post above) and it appears in Sahi's temp directory..

    Another question related to this, is if it is possible to retrieve the URI of the last downloaded file in my test script? (I see it being logged at the console). This is because our stats-trigger.gif is called with a querystring containing information I would like to be able to verify. - see post above, but I trimmed some of the querystring to not reveal too much info about the company I work for :-)
  • I am having the same problem. I really want this to work, Sahi Pro is sooo fast with our application...

    -- Calling downloadFile --
    https://qad.XXXXX.net/Reports/frmShowReport.aspx?PdfFileName=\\192.168.5.80\
    BTReports\f5c2181a-58a8-42f4-8e97-f33282885e07.PDF
    downloadURL = false
    response.isAttachment() = true
    fileName = f5c2181a-58a8-42f4-8e97-f33282885e07.PDF
    contentTypeHeader = application/pdf
    downloadContentType = true
    Content-Disposition=attachment; filename=f5c2181a-58a8-42f4-8e97-f33282885e07.PD
    F
    contentDispositionForcesDownload = true
    --
    Jan 07, 2013 2:50:57 PM net.sf.sahi.RemoteRequestProcessor save
    INFO: Downloading sahi_e7ef8fbd017e9046aa080b207067cc489c6f__f5c2181a-58a8-42f4-
    8e97-f33282885e07.PDF to temp directory:
    C:\sahi_pro\userdata\temp\download
    Jan 07, 2013 2:50:57 PM net.sf.sahi.RemoteRequestProcessor downloadFile
    INFO: Setting download_lastFile = f5c2181a-58a8-42f4-8e97-f33282885e07.PDF
    Session Id: sahi_e7ef8fbd017e9046aa080b207067cc489c6f

    The code below fails everytime because $fileName is null. The file is in the downloads folder, sahi_e7ef8fbd017e9046aa080b207067cc489c6f__f5c2181a-58a8-42f4-8e97-f33282885e07.PDF
    var $fileName = _lastDownloadedFileName();
    _alert($fileName);
    var $names = $fileName.split("\"");//gives you the name of downloaded file if you want to use it
    _log($names);
    _saveDownloadedAs("C://sahi_pro//userdata//scripts//CMN.pdf"); // change this path to your scripts folder
    

  • BTW, the resolution was to add a 5 second wait to my script...
Sign In or Register to comment.