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.

Verify the file format

edited November 2013 in Sahi - Open Source
Hi ,

I have downloaded a pdf file from my application.
Is there any way to verify the file format is pdf ?
Please help me on this.

Best Answer

  • try using :-
    var $filename= _lastDownloadedFileName();
    and verify .pdf is present in the filename

    Regards,
    Bhavitha

Answers

  • thanks for ur reply. i'm having a concern in this.

    1. downloading the file and saving it in diff. location.
    2. after tat i'm verifying the file format.

    when fetching teh file name using a variable , its showing as "downloadData" , not the file name which i saved.
    Please help me.

    Regards,
    Sindhu.
  • Try this:-
    _clearLastDownloadedFileName();
    var $downloadedFile= _lastDownloadedFileName();
    _saveDownloadedAs("D:\\folder\\"+$downloadedFile);

    Regards,
    Bhavitha
  • Whether the below code is fine ? Correct me if i'm wrong ?

    var $downloadedFile= _lastDownloadedFileName();
    _saveDownloadedAs("C://Users//lakshmsn//Desktop//SVN//Trackers//Automation//RM//Sprint8//+$downloadedFile");
    _clearLastDownloadedFileName();
    _assertContainsText("/.*pdf/", $downloadedFile);
  • use the script in below order
    _clearLastDownloadedFileName();
    var $downloadedFile= _lastDownloadedFileName();
    _saveDownloadedAs("C://Users//lakshmsn//Desktop//SVN//Trackers//Automation//RM//Sprint8//+$downloadedFile");
    _assertContainsText("/.*pdf/", $downloadedFile);

    if the last line script does not work, use substring to fetch ".pdf" and compare

    Thanks,
    Ashokan.P
  • thanks for ur reply ashok.

    It dint work. Its taking file name as 'null' when validating the text.
    _assertContainsText("/.*pdf/", null);

    Regards,
    Sindhu L.
  • I guess none of the file is downloaded, and thats why the _lastDownloadedFile is showing as null.
    can you verify if actually file is getting downloaded.
  • Can you please check if your "download_contenttypes.txt" file contains pdf ? if not the file download will not be recognised and lastDownloadedFile() returns null.
    The file is available at

    ",SAHI_INSTALLATION_FOLDER/sahi_pro/config/userdata_template/config"
Sign In or Register to comment.