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.

this.topSahi() is undefined

felixfelix Members
edited November -1 in Sahi - Open Source
Operating system: Windows 7 Professional
Browser: Firefox 7.0.1 and firefox 8.0.1
Sahi build: 2011-07-19

I have a simple sahi script that logs in to our application, logs out, logs back in, and logs out. On the second log in, straight after Sahi clicks on the Login button, I get the following error on the command line:

Debug: concat.js: Diff domain: Could not add XHR to list for automatic monitoring TypeError: _sahi.topSahi() is undefined

The home page loads correctly, but no further sahi commands are executed and Sahi becomes unresponsive. When I hold "Ctrl" and hover over any elements, Sahi does not show anything. If I close the Sahi controller, holding "Alt" and double clicking does not bring it back up, unless I manually log out first.

Interestingly, if I run the same script in firefox 3.6.24, it runs perfectly, and the error does not show.

Thanks in advance for your help.

Felix

Comments

  • Hi felix,

    Kindly have a look at : http://sahi.co.in/forums/viewtopic.php?id=3145

    For controller not coming up:

    Have a look at :

    http://sahi.co.in/w/trouble-shooting-sahi

    http://sahi.co.in/w/https-ssl

    Are you facing this issue on other browsers as well.

    Regards
    Sumitra
  • felixfelix Members
    edited February 2012
    Hi Sumitra,

    thanks for your response!

    I had had a look at the first link. As that was the only error message showing when sahi stopped responding, I hoped that it might be the cause. Does the post mean that although that error shows up, it is not the problem at all?

    I also had a look at the trouble shooting link, and tried the instructions under "Playback starts but keeps waiting on some page", but that did not help either.

    The third link for https-ssl I don't think applies.

    Yes, I tried the same thing on ie8 and encountered a similar problem. The first login works fine, but after the second login ie comes up with the warning "server is not trusted", and that the url should be added to trusted sites. Making the url trusted does not help.

    I thought it has something to do with cookies or the cache, but clearing these does not help either.

    Another thing I tried is force refreshing (Ctrl + F5) twice before logging out. I did this by making a sahi _alert() before logging out, pausing the script, manually force refreshing twice, and then clicking 'play' to continue the script. This fixed the problem for both ie8 and ff9.

    However, when I tried to automate this using a java robot to do the force refresh for me, sahi became unresponsive after the second forced refresh (without even logging out) for both ie8 and ff9. Interestingly, on ie8 sahi simply stopped responding, where before on the the second log in the "server not trusted" warning was displayed as well as sahi not responding.

    Thanks in advance,

    Felix
  • felixfelix Members
    edited February 2012
    Hi Sumitra,

    we finally came up with a work around! We did two things:

    1. As mentioned above, a manual double refresh after sahi froze would allow sahi to continue. Automating this using sahi did not work, as sahi was already frozen. So we injected javascript that would refresh on the home page directly into the browser:
    <browser>
    setTimeout('refreshHomePage();',8000);
    function refreshHomePage() {
        if ( document.getElementById("EntryPointName").innerHTML == "User Homepage" ) {
            top.location.reload();// ie 7,8,9
        }
    }
    </browser>
    

    When sahi freezes after logging in, the javascript causes a refresh. 8 seconds later, the second refresh occurs. Then sahi continues.

    This fixed our problem with firefox 7 to 10.


    2. We still got the "server not trusted" error with ie though. Here we fiddled around with concat.js (found in <Sahi install directory>\htdocs\spr\concat.js) and made the following changes:

    Change 1: from line 2301
    ========================================
    Sahi.prototype.isRecording = function () {
        if (this.topSahi()._isRecording == null)
            this.topSahi()._isRecording = this.sendToServer("/_s_/dyn/SessionState_isRecording") == "1";
        return this.topSahi()._isRecording;
    };
    
    ---------------to-------------------------
    Sahi.prototype.isRecording = function () {
            if (this.topSahi() == null) {
                    return null;
            }
        if (this.topSahi()._isRecording == null)
            this.topSahi()._isRecording = this.sendToServer("/_s_/dyn/SessionState_isRecording") == "1";
        return this.topSahi()._isRecording;
    };
    ==========================================
    
    Change 2: from line 3625
    ========================================
    SahiXHRWrapper = function (s, isActiveX){
            try{
                    this.xhr = isActiveX ? new_ActiveXObject(s) : new real_XMLHttpRequest();
            }catch(e){
                    if (_sahi._isIE() && window.ActiveXObject){
                            this.xhr = new_ActiveXObject("Microsoft.XMLHTTP");
                    }
            }
        var xs = _sahi.topSahi().XHRs;
        xs[xs.length] = this;
        this._async = false;
    };
    ---------------to-------------------------
    SahiXHRWrapper = function (s, isActiveX){
            try{
                    this.xhr = isActiveX ? new_ActiveXObject(s) : new real_XMLHttpRequest();
            }catch(e){
                    if (_sahi._isIE() && window.ActiveXObject){
                            this.xhr = new_ActiveXObject("Microsoft.XMLHTTP");
                    }
            }
            if (_sahi.topSahi() != null) {
                    var xs = _sahi.topSahi().XHRs;
                    xs[xs.length] = this;
            }
        this._async = false;
    };
    ==========================================
    
    Change 3: from line 3637
    ========================================
    SahiXHRWrapper.prototype.open = function(method, url, async, username, password){
        url = ""+url;
        this._async = async;
        var opened = this.xhr.open(method, url, async, username, password);
        if (url.indexOf("/_s_/") == -1){
            try{
    
                var xs = _sahi.topSahi().XHRs;
                xs[xs.length] = this;
    
            }catch(e){}
            this.xhr.setRequestHeader("sahi-isxhr", "true");
        }
        var fn = this.stateChange;
        var obj = this;
        this.xhr.onreadystatechange = function(){fn.apply(obj, arguments);}
        return opened;
    };
    ---------------to-------------------------
    SahiXHRWrapper.prototype.open = function(method, url, async, username, password){
        url = ""+url;
        this._async = async;
        var opened = this.xhr.open(method, url, async, username, password);
        if (url.indexOf("/_s_/") == -1){
            try{
                            if (_sahi.topSahi() != null) {
                                    var xs = _sahi.topSahi().XHRs;
                                    xs[xs.length] = this;
                            }            
            }catch(e){}
            this.xhr.setRequestHeader("sahi-isxhr", "true");
        }
        var fn = this.stateChange;
        var obj = this;
        this.xhr.onreadystatechange = function(){fn.apply(obj, arguments);}
        return opened;
    };
    ==========================================
    

    This prevents the error we previously got "Debug: concat.js: Diff domain: Could not add XHR to list for automatic monitoring TypeError: _sahi.topSahi() is undefined". Combined with the refresh work around, this fixes our problem for ie as well!

    Hope this is useful to someone. Let me know!

    Cheers,

    Felix
Sign In or Register to comment.