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.

Sahi (Windows Pop-UP) support

diikeediikee Members
edited November -1 in Sahi - Open Source
Does anyone know how to code Sahi to download a file, populate the "Save As" windows prompt, click "Save" and if file exist, click "Yes" to overwrite???

this is a huddle in getting my script to fully work.
Test case
- Click on a button on a page
- windows "Save As" prompt pops up
- select the c:\mine as the directory
- enter a name for the file
- click Save

If the filename exists
- an overwrite prompt pops up
- click on "Yes" to overwrite

code samples would be helpful

Comments

  • narayannarayan Administrators
    Working on this. Expect a post and build soon.
  • diikeediikee Members
    Narayan, how we doing on this Window "Save As" item??

    this will be a great enhancement to Sahi and sure a lot of users will make use of the feature.
  • narayannarayan Administrators
    A day more, diikee; almost there. Thanks.
  • diikeediikee Members
    thanks for your reply, this will help alot....
  • diikeediikee Members
    Any progress on this issue?? Still waiting
  • Hi Narayan,

    Any updates on "Save as" dialog box?

    Regards,
    Pankaj.
  • Hi Narayan,

    Please suggest any workaround to tackle the save as dialog box. I am not able to use the latest sahi due to some iframe related issue. Or any readings from where i can have an idea how the browser handles save as dialog box.

    Regards,
    Pankaj.
  • narayannarayan Administrators
    OK, for save as:

    There is a file called download_contenttypes.txt in sahi/config folder.
    Add content types you want downloaded into that file.
    The format is:

    1) One content type per line
    2) Just add one word from the content type.

    Eg.

    octet
    doc
    excel

    This will store the file into sahi/temp

    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.txt"); // save to another path
    _clearLastDownloadedFileName(); // clear the variable
    _assertNull(_lastDownloadedFileName()); // check to see if cleared.
    
    I had been refraining from making this public because it is largely untested. If you intend to use it, do give feedback.

    There is also another file called config/download_urls.txt which takes urls that need to be downloaded instead of content types.
    Format:
    regexp of url

    Eg.
    .*/setup[.]exe
    .*/docs[.]zip
  • narayannarayan Administrators
    Pankaj, could you start another thread with the iframe problem? Let us get that fixed too.
  • pankaj.nithpankaj.nith Members
    edited September 2008
    Sure Narayan :)
    Is this solution for save as working in the latest build or it worked earlier also? Actually i m using an old version of sahi.
    And thanks for all the valuable inputs.

    Regards,
    Pankaj.
  • Test :
    There is a "Save As" button. When we click on the button, the html page the Save-as dialog pops up. I need to write a script to save the html file in the desktop.

    So, in the In download_contenttypes.txt in sahi/config folder , i added content type as "html".

    Code :
    _click(_link("Display-UsrInfo"));
    _assertNull(_lastDownloadedFileName());
    _click(_button("Save As"));
    _assertEqual("setup.exe", _lastDownloadedFileName());
    _saveDownloadedAs("C:/Documents and Settings/Desktop/user-history.html"); // save to another path
    _clearLastDownloadedFileName();
    _assertNull(_lastDownloadedFileName());

    But the file is not getting downloaded.

    Can anyone please check this.
  • PriyaPriya Members
    edited December 2008
    Hi Narayan,

    I am also struck here
    Please let me know if any proceedings on this issue
    The issue is with 'Save' button, sahi is unable recognise Save button on windows 'File Download' pop-up.

    Thanks and Regards
    Priya.
  • narayannarayan Administrators
    Priya,
    Did you try the _lastDownloadedFileName, _saveDownloadedAs and _clearLastDownloadedFileName APIs as said in the above post?
    Sahi will not recognize the save as dialog while recording. But if you do the following, the dialog will not come up during playback.
    Set the the content type to be downloaded in sahi/config/download_contenttypes.txt and restart Sahi. During playback, you will no longer be presented with the Save As dialog. The file would automatically be downloaded to sahi/temp/download directory. You can then assert if the file was downloaded using _lastDownloadedFileName. You can rename the file using
    _saveDownloadedAs and can clear the downloaded file using _clearLastDownloadedFileName. Look at the my previous post for usage.

    If you still have doubts, ping back.
  • Hi Narayan,

    I have tried with above APIs, it says success but file is not downloaded.
    Below is the script that i have used,

    _click(_imageSubmitButton("Search Subscriber"));
    _wait(4000);
    _click(_imageSubmitButton("Search"));
    _wait(4000);
    _click(_imageSubmitButton("Export"));
    _wait(4000);
    _assertNull(_lastDownloadedFileName());
    _click(_image("formFileTypes:exportImage"));
    _saveDownloadedAs("D:\\Myfolder\\myfile.xls");
    _clearLastDownloadedFileName();
    _assertNull(_lastDownloadedFileName());
  • narayannarayan Administrators
    Priya, do you see errors on the proxy console? Btw is the file very big?
  • Hi Narayan,

    I am getting these statements in the console,when i run this script.And the size of the file is only 9.54 KB .

    tempDownloadDir ../temp/download
    tempFileName null
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.sf.sahi.command.CommandExecuter.execute(CommandExecuter.java:52)
    at net.sf.sahi.LocalRequestProcessor.getLocalResponse(LocalRequestProces
    sor.java:42)
    at net.sf.sahi.ProxyProcessor.processLocally(ProxyProcessor.java:206)
    at net.sf.sahi.ProxyProcessor.run(ProxyProcessor.java:71)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NullPointerException
    at java.io.File.<init>(Unknown Source)
    at net.sf.sahi.util.Utils.concatPaths(Utils.java:159)
    at net.sf.sahi.command.SaveAs.saveLastDownloadedAs(SaveAs.java:27)
    ... 9 more
    Rhino lib:script ended.
    End of script
  • Hi Narayan,

    Still I can see the window file download window. Here goes my script-

    _assertNull(_lastDownloadedFileName());
    _click(_popup("PaymentLounge")._button("Download Form"));
    _saveDownloadedAs("c:/path/FACEBOOK.pdf");
    _clearLastDownloadedFileName();
    _assertNull(_lastDownloadedFileName());
    Here I am not getting error due to the file download scenario but script fails due to not executing the rest of the scripts. And the file download box remains showing.

    I changed in
    SAHI\userdata\config\-- download_contenttypes and also change in download_urls

    download_contenttypes contains-
    zip
    excel
    doc
    application/vnd.ms
    application/ms
    application/octet-stream
    pdf

    Please do let me know where I am doing wrong.

    Gyanadeep
  • Hey the issue resolved. I did the following thing-

    Add two thing in download_urls.txt
    .*/[.]pdf
    .*/[.]html

    Add -
    application/.pdf

    And below is the code-


    _popup("PaymentLounge")._click(_button(4));

    _wait(9000);
    _saveDownloadedAs("c:/path/"+$FileName+".pdf");

    Here one issue is the browser (blank) is not closing and for next transaction it is using that browser. So can you please tell me how we can close that browser in sahi.Because that browser usually close when u save the file in manually.

    And another help is how can i verify the file is created in my respective folder.
  • But in one case I am having issue and that is - I have 5 diff country and for that i am downloading 5 different PDF . But for my first country it is downloading 0 kb PDF and rest of it is downloading the actual PDF. here goes the code-

    var $FileName= $CountryCode+"Mandate"+ _random(10000)

    _popup("PaymentLounge")._click(_button(4));

    _assertNotNull(_lastDownloadedFileName());

    _saveDownloadedAs("c:/path/"+$FileName+".pdf");
    _wait(20000);


    If i am using _assertNull(_lastDownloadedFileName()); then it is downloading all my PDF with size 0kb. So I have removed that part from my script.

    Any thoughts around this.

    Gyanadeep
Sign In or Register to comment.