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.

JSERROR ReferenceError: "_log" is not defined

edited November -1 in Sahi - Open Source
I'm getting an error message calling the _log function in my script.

First off, I am a little confused about this function - is it part of the API or not? It's listed in 'scheduler_functions.txt' but it is not in the API web page.

Secondly, I am getting the error message

"JSERROR ReferenceError: "_log" is not defined"

in the log file when I try to use it. I have seen many posts on this forum with people using the function, so it seems that they all know something I don't! I am trying to use this function because I am getting an absurd error in a later script which claims a similar error message when I call _assertExists(). For some reason, when I call this function from within a certain .sah script file it fails, but if I comment out the line and move it into the calling script, it executes...

The same is true of any of the usual core functions such as _assertTrue. i am trying to find some way, with _log(), to debug what is going wrong. At the moment, the only issue I can see is that Sahi is not wrapping calls to _log() and _assertExists() in _sahi.schedule()

Problem lines:
_log.("TEST");
_sahi._assertExists(_sahi._byId("dialog0"));

Normal:
_sahi.schedule("_sahi._assertExists(_sahi._cell(_sahi._table(1), 1, 0));", "D:\\sahi\\start.sah&n=6");

Can anyone shed some light on this?

I am using Sahi (Build: 2009-01-21)

Comments

  • narayannarayan Administrators
    Corrected code
    _log("TEST"); // no period before bracket. _log.("TEST");
    _assertExists(_byId("dialog0"));   // You should not add _sahi. to these functions. Sahi will automatically add it.  _sahi._assertExists(_sahi._byId("dialog0"));
    
  • Thanks for the quick reply!

    Let me clarify. I have a root script which is calling a sequence of other scripts in order to test a feature:
    _include("../../common/login.sah"); 
    _include("../../common/logout.sah");
    _include("../timeframe/gotoTimeframePage.sah");
    _include("../timeframe/setTimeframe.sah");
    _include("waitForPageToLoad.sah");
    _include("testCallLogSearchResults.sah");
    
    _continueOnError();
    
    logout();
    
    login("speechdial", "speechdial;");
    
    gotoTimeframePage();
    
    setFormValsAndSubmit("01/01/09 07:25", "01/01/09 07:27");
    
    waitForPageToLoad();
    
    verifyCallLogSearchResults();
    //_assertExists(_byId("dialog0"));    // ALTERNATIVE
    
    logout();
    
    The function verifyCallLogSearchResults() is contained in the following testCallLogSearchResults.sah:
    function verifyCallLogSearchResults()
    {
    
        checkDialogExists();
    }
    
    function checkDialogExists()
    {
        // Check the dialog exists
        _assertExists(_byId("dialog0")); // ERROR LINE
    }
    
    When 'ERROR LINE' is called, I get the error message "JSERROR TypeError: Cannot find function _assertExists". If I comment it out, the code runs fine. If i move the same line to the parent script at 'ALTERNATIVE' it runs fine.

    To summarise, the _assertExists() function seems to disappear...

    Apologies for my original post - I think it led you on a wild goose chase...
  • I have done something similar to what you are trying to do
    <browser>
    function logoutLinkExists()
    {
        return _containsText(_byId("footerContents"), "You are currently logged in... welcome back");
    }
    </browser>
    
    function Login($username, $password, $emailaddress)
    {
        var $exists;
        _set($exists, logoutLinkExists());
        while ($exists)
        {
            clickLink("Logout");
            _set($exists, logoutLinkExists());
        }
    
        setTextBoxValue(null, "ctl00\$ContentPlaceHolder1\$Login1\$UserName", $username);
        setPassword("ctl00\$ContentPlaceHolder1\$Login1\$Password", $password, null);
        setTextBoxValue(null, "ctl00\$ContentPlaceHolder1\$Login1\$Email", $emailaddress);
        clickSubmit(null, "Log In", null);
    }
    
    I am guessing that where you could substitute my _containsText with your _assertExists and achieve the same results. but the function must be called within a _set Statement as shown on line 2 of my Login function.

    Hope this is of help

    Donna
  • niveditanivedita Members
    Thanks Donna, this helped me. I was doing something like this before:
    <browser>
            function returnFive() {
                       return 5;              
            }
    </browser>
    
    var $number = _call(returnFive());
    _setValue(_textbox("five"), $number);
    

    Which was throwing me a JSERROR ReferenceError

    I changed it to how you suggested I call a function to set a variable's value.
    var $number;
    _set($number, returnFive());
    _setValue(_textbox("five"), $number);
    

    And it worked fine.

    So looks like _call cannot be used for setting variable values? Wish this was documented better.
  • narayannarayan Administrators
    Hi Nivedita,

    Thanks for the feedback on the documentation. Could you please check now to see if it is any better?

    http://sahi.co.in/w/_set
    http://sahi.co.in/w/_call

    Thanks and regards,
    Narayan
  • Sure, documentation for _call and _set explains this behavior much better now, thanks.

    Just wondering aloud here, wouldn't it be a good idea to have a wiki for the documentation so that users can update the documentation themselves?
Sign In or Register to comment.