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.

testing webservices from sahi works !!! (XMLHttpRequest)

zawistolzawistol Members
edited November -1 in Sahi - Open Source
hi,
I had success running webservices simple example from sahi using XMLHttpRequest (js library)
Configuration: Firefox 3.6 + sahi_20110719
Here is how in 3 steps


1. append to concat.js
Sahi.prototype._webServiceRequest = function (url) {
request = new XMLHttpRequest();
request.open("POST", "http://myserver.com/ws/",false);
request.setRequestHeader("Content-Type", "text/xml");
request.send("<StatusRQ  versionNumber=\"1.0.0\" xmlns=\"http://myserver.com/ns/myapp/V1\"><RequestID>670222</RequestID></StatusRQ>"); 
return true;

2. append to normal_functions.txt
_webServiceRequest


3. run from sahi console - important, the url should be within: "http://myserver.com/"
_webServiceRequest();
Should get "true" response

Thanks Raman for telling me this should be possible
Now there is a lot of work, to make it "out of box solution" :)
Have fun!
Lech

Comments

  • You can test Web services by calling Web methods from unit tests. Testing Web services is much like testing other code by using unit tests in that you can use Assert statements, and the tests produce the same range of results.
  • The final function that we use now (thanks to Piotr) looks like this
    (add to concat.js and normal functions of sahi 3.5)
    Please note it may not work with your webservice because of different
    Envelope and headers
    Sahi.prototype._webServiceRequest = function (url, XMLdata, ath) {
        
        try
        {
            request = new XMLHttpRequest();
        }
        catch (e)
        {
            return false;
        }
        
        request.open("POST", url, false);
        request.setRequestHeader("Content-Type", "text/xml");
        request.setRequestHeader("ATH", ath);
        request.send(XMLdata);
        
        var response = {};
        
        response.statusText=request.statusText;
        response.status=request.status;
        response.responseText=request.responseText;
    
        return response;
    };
    

    then in sahi script we use
    WebServices.prototype.webServiceLoadRequest = function(XMLRequest, $Name)
    {
        _log("Send XML message", "custom5");
        var $sendXML = "";
        var $responseText = "";
        var $athHeader = this.getATHHeader();
        var $requestID = "";
        var $url = this.getEndPoint();
        
        var $XMLLoadRQ = XMLEnvelope.replace("{XMLSoapHeader}", XMLSoapHeaderLoadRQ).replace("{request}", XMLRequest).replace("{Name}", $Name);    
        $sendXML = $XMLLoadRQ.replace( /</g, "&lt;" ).replace( />/g, "&gt;");
        _log("<PRE>" + $sendXML + "</PRE>");
    
        _set($response, _webServiceRequest($url, $XMLLoadRQ, $athHeader));
        $responseText = $response.responseText.replace( /</g, "&lt;" ).replace( />/g, "&gt;");
        _log("<PRE>" + $responseText + "</PRE>");
        _assertEqual($response.statusText, "OK");
        //_assertEqual($response.status, 200);
        
        $requestID = $response.responseText.match(/[0-9]{7}/)[0];
        _log("<PRE>" + "RequestID: "+ $requestID + "</PRE>");
        return $requestID;
    };
    
    
  • I learned a lot from your post.Thanks a lot.
    You can test Web services by calling Web methods from unit tests. Testing Web services is much like testing other code by using unit tests in that you can use Assert statements, and the tests produce the same range of results.
This discussion has been closed.