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.

Windows open, save, close hanging and not saving file

InstinctInstinct Members
edited November 2009 in Sahi - Open Source
I'm fairly new to automated web testing, never mind Sahi itself.
I've ran into a problem playing back a recorded automated test.

On a web page we've got a print button, what this button does is generate a pdf file in the background from all the form information and displays the windows Open, save, close dialog box. I'm at the point that I've modified the download_contentypes.txt file with pdf and added

_assertNull(_lastDownloadedFileName()); // nothing so far
_click(_submit("Print"));
_saveDownloadedAs("G:\WebTesting\Webtest.pdf"); // save to another path
_clearLastDownloadedFileName(); // clear the variable
_assertNull(_lastDownloadedFileName()); // check to see if cleared.

to my script. The save dialog is no longer displaying during playback as expected. However, it hangs on the _click(_Submit("Print")); never goes any further and fails with JSERROR [object Object] at 2-Nov-2009 2:57:43 PM in the error log and Rhino lib:### Step did not return in 130 seconds. in the proxy window.

Also after turning debug.traffic.log = true
in the proxy window I get this.

responseFromHost.contentTypeHeader()=application/pdf
Content-Disposition=attachment; filename="Super1257188474836.PDF"
isDownloadURL: mywebserver/PDCAS/manageCase.do - false
Downloading sahi_5606f8d20b28e04fca09684001e967f9574a__manageCase.do to temp
directory: c:\sagi\temp\download
Setting download_lastFile = manageCase.do
Session Id: sahi_5606f8d20b28e04fca09684001e967f9574a

Obviously I want Super1257188474836.PDF downloaded once generated and not the action manageCase.do.
Also _saveDownloadedAs("G:\Webtest\Webtest.pdf"); // save to another path
never creates Webtest.pdf as entered in the script.

I've got a demo scheduled for this Wednesday to my Supervisor and Manager and would like to get over this problem.

Any help would be greatly appreciated.

Thanks in advance..

ps: I should add that this problem is in IE6, Firefox 3.0.1.4 as well as Eclipse's internal web browser.

Comments

  • Hi,

    Instead of accessing the Print button element using _submit function, Please try accessing the element using any alternative functions like _link,_image,etc

    Hint: Open sahi controller's Record tab, Press ctrl key and mouse over the print button.In Accessor text box value, You can see how the element is being accessed in sahi.

    For Example, please run the below sahi script by setting http://sahi.co.in/demo as start url

    _click(_link("Form Test"));
    _click(_submit("Button Two"));

    You can see _click & _ submit working fine.

    Also make sure, whether the print button is a submit button in your page or not when you use _click(_submit("Print")) .

    can you specify which version of sahi you are using?

    Let us know, whether it helps or not.

    Thanks,
    Venky.
  • Version of Sahi Build 2009-09-22

    I actually tried that yesterday regarding that I should make sure that it is indeed a _submit function and it's definitely a _submit("Print") function that is needed. I did ctrl key and mouse over thing as you asked and it's accessor text value and alternative text values are _submit("Print")

    As stated below it looks like it recognizes the file that was generated,

    responseFromHost.contentTypeHeader()=application/pdf
    Content-Disposition=attachment; filename="Super1257188474836.PDF"

    However, it looks like it wants to verify that it exist on the page.

    isDownloadURL: mywebserver/PDCAS/manageCase.do - false

    Then I guess it assumes that it is the page itself I want to download which is not the case

    Downloading sahi_5606f8d20b28e04fca09684001e967f9574a__manageCase.do to temp
    directory: c:\sagi\temp\download
    Setting download_lastFile = manageCase.do

    At this point I'm still stuck, if only it didn't hang there I could probably convince the people that the improper file that is downloaded could be worked around, however this will probably make it or break it for my presentation tomorrow for my supervisors and manager.

    Let me know if you have any other suggestions.

    Thanks
  • Anyone? It's 5:00pm and my presentation is at 1:00pm tomorrow. I really need to resolve this issue if I'm going to sell Sahi to my supervisors and manager.

    Thanks
  • VenkyVenky Members
    edited November 2009
    Yes you are right, It recognizes the file that it has to download and some how it is not picking the download url. We need to see how your page works, so can you email me when you are back to work. Then you can share your screen to us through skype in order to resolve this issue on sahi by knowing the functionality of your page.

    Try introducing
    _wait(4000);
    _navigateTo(<The url where your generated pdf resides>);
    _click(_link(<file name>));

    before _saveDownloadAs(..) because it might take few time to generate your pdf right.

    Let us know, if you still have any problems.

    Thanks,
    Venky.
  • Thanks guys. I was able to convince my organization to adopt Sahi for our automated web testing. When I have some time at home (work won't let me let none employees remotely connect ie: Skype) we will have to get together to resolve my file download issue.

    Venky,
    The code you suggested I use will not work in our situation.

    _navigateTo(<The url where your generated pdf resides>);

    The PDF never actually resides at any url. It is generated on the fly and prompts the user to save/open/cancel.

    And again

    _click(_link(<file name>));

    The file is never available to actually click on.

    Anyway, as soon as I get an environment setup at home, we'll get together to hopefully resolve this issue. Cause so far it is the only one that I've found.

    Thanks again
  • In the mean while, Please have a look at <sahi base dir>\userdata\scripts\demo\save_as.sah script file. Try modifying it according to the way as you need & in the way your page works.

    Inform us, when we can able to work together. We are very glad to help you.

    Thanks,
    Venky.
  • narayannarayan Administrators
    Instinct,

    Glad you could convince your management in spite of no resolution to this issue.

    Some comments:

    Sahi IS able to click and identify the file as something that needs to be downloaded and actually does download the file.
    Downloading sahi_5606f8d20b28e04fca09684001e967f9574a__manageCase.do to temp

    But the next line where you specify

    _saveDownloadedAs("G:\WebTesting\Webtest.pdf");

    is incorrect because back slashes need to be escaped in a string. So do:

    _saveDownloadedAs("G:\\WebTesting\\Webtest.pdf");
    or
    _saveDownloadedAs("G:/WebTesting/Webtest.pdf");

    I will check why it gives an object object error.

    Also, do give a wait after your _click(_submit("Print"));

    So your script should look like this:

    _assertNull(_lastDownloadedFileName()); // nothing so far
    _click(_submit("Print"));
    _wait(10000); // Introduce a wait based on how big your download file is.
    _saveDownloadedAs("G:\\WebTesting\\Webtest.pdf"); // save to another path; escape back slashes
    _clearLastDownloadedFileName(); // clear the variable
    _assertNull(_lastDownloadedFileName()); // check to see if cleared.

    The rest should work fine.

    One thing to notice is that Sahi actually uses only the download URL filename as the file name rather than the file name specified in the content-disposition header's filename. This needs to be fixed in Sahi. (Expect it in the next build).

    Regards,
    Narayan
  • hooray!!!!!!!!!

    Thanks Narayan and Venky for all the help.
    The following code from narayan worked like a charm

    _assertNull(_lastDownloadedFileName()); // nothing so far
    _click(_submit("Print"));
    _wait(10000); // Introduce a wait based on how big your download file is.
    _saveDownloadedAs("G:\\WebTesting\\Webtest.pdf"); // save to another path; escape back slashes
    _clearLastDownloadedFileName(); // clear the variable
    _assertNull(_lastDownloadedFileName()); // check to see if cleared.

    The combination of the _wait and the proper escape back slashes did the trick.

    Thanks again. :)
  • One quick question.

    Is there a way to extract the name of content-disposition header's filename ie:"Super1257188474836.PDF" and use it for the _saveDownloadedAs("G:\\WebTesting\\Webtest.pdf");

    Thanks again for all the great help. One day, maybe I'll come up with a solution for the community.
  • narayannarayan Administrators
    Instinct,

    As of now, you cannot use the name in the content-disposition header. But using the header seems to be the correct way to get the file name. As I said, we will add it to the next build, and will send you an early access build as soon as we fix it.

    Regards,
    Narayan
Sign In or Register to comment.