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.

How to write to the wordFile using "writeToFile" function?

aspatel80aspatel80 Members
edited November -1 in Sahi - Open Source
Hello team

I have tried to write to the word file using _writeToFile( ) function but it gives me the erroe that it is undefined.

Can you please give me a code to write the test result in external file?


Ashvin

Comments

  • narayannarayan Administrators
    Ashvin, which version of Sahi are you using?
    Check if _writeToFile is present in these two files:

    sahi/htdocs/spr/concat.js
    sahi/config/normal_functions.txt

    If not, you are using an older version of Sahi and may need to either get the latest, or copy over the necessary function. (It should not be a big hassle.)
  • Hi Narayan,

    As per your suggestion I have downloaded the SAHI version of 15-July-2009. And I found that 'Contact.js' doesn't contain _WriteToFile function but it contain in the 'normal_functions.txt' file.

    Can you please confirm the same?

    Thanks,

    Ashvin
  • How can we use following code in SAHI?

    <SCRIPT LANGUAGE="JavaScript">
    function WriteToFile(passForm) {

    set fso = CreateObject("Scripting.FileSystemObject");
    set s = fso.CreateTextFile("C:\test.txt", True);
    s.writeline("HI");
    s.writeline("Bye");
    s.writeline("
    ");
    s.Close();
    }
    </SCRIPT>


    Regards,

    Ashvin
  • narayannarayan Administrators
    Ashvin,

    Scripting.FileSystemObject is available on the browser but will not work because of security restrictions.

    I was wrong in stating that the function would be in concat.js.
    It should be in sahi/htdocs/spr/lib.js

    If not, you could just add this to lib.js:

    Sahi.prototype._writeFile = function (str, filePath, overwrite) {
    overwrite = (overwrite == true);
    return "" + Packages.net.sf.sahi.util.Utils.writeFile(str, filePath, overwrite);
    };
    Sahi.prototype._writeToFile = Sahi.prototype._writeFile;
Sign In or Register to comment.