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.

writeFile with Global variables

NEWUSERNEWUSER Members
edited November -1 in Sahi - Open Source
Hi,
When i am trying to use writeFile with getGlobal it is now working.
The mentioned file is present in the path and when i try ro append some test on it, it is now working.

_setGlobal("LogFile","C:\\Log_01Oct20.log");
_alert(_getGlobal("LogFile"));
_writeFile("Testing Attention Please\r\n" ,_getGlobal("LogFile"));

Error Message:
JSERROR Wrapped java.lang.NullPointerException

However when i use this: _writeFile("Testing Attention Please\r\n" ,"C:\\Log_01Oct20.log") its working.

Comments

  • I am had tried using _debugToFile with get global and it is working properly but problem with that is it every time i use it, it inserts returen character at end. so if i have a typical scenario like below _write will be much better to use.

    _debugToFile("Testing" ,_getGlobal("LogFile"));
    Some statements
    _debugToFile("Attention" ,_getGlobal("LogFile"));
    Some more statements
    _debugToFile("Please\r\n" ,_getGlobal("LogFile"));
  • any comments 4m ny1?
  • dpdp Members
    The following should work
    var $myPath = "C:\\Log_01Oct20.log";
    
    _writeFile("Testing", $myPath);
    _writeFile("Attention", $myPath);
    _writeFile("Please", $myPath);
    
  • I cannot use this. I have 2 seperate SAH files say A and B. B is included in A. So when execution goes to B then this variable will not be assicible any more.
  • narayannarayan Administrators
    Editing my original comment:

    1) The variable will be accessible even in included B, since included files are all flattened out into a single script by Sahi.
    2) _getGlobal and _setGlobal are not very useful since Sahi V2. Just define a variable and use it the way DP suggests. If it does not work, let us know.

    Regards,
    Narayan
  • OOhhh... i was thinking it would not allow. gr8. Worked for me
    Thanks Dp & Narayn
This discussion has been closed.