Search code examples
javascriptperformance-testingfunctional-testing

How to prevent WebLOAD wlHttp module from aborting round when receiving non-200 status code?


I've been recently tasked with working in WebLOAD in order to test the functionality of an API. Alternatives to WebLOAD can't be used for the task due to the project's requirements.

Some of the test cases I've been tasked with writing involve submitting a malformed request and ensuring that a 400 response code was returned. My problem is that every time a non-200 response is received, wlHttp throws an error in the console and aborts the current round.

I've tried surrounding the wlHttp.Get call with a try/catch but that didn't work. Any help would be very much appreciated, as judging from this document it seems like it should be possible to continue after receiving a non-200 status code.

Below is an MVP similar to the code I'm writing for my test cases. In the console output (below the MVP) you can see that "1" was logged however execution stopped immediately after the error concerning the 400 was logged with console.log("2") never being ran.

function InitAgenda() {
    wlGlobals.GetFrames = false;
    wlGlobals.SaveSource = true;
    wlGlobals.SaveHeaders = true;
}

/***** WLIDE - ID:5 - JavaScript *****/

wlHttp.ContentType = "application/json";

console.log("1");
wlHttp.Get("https://httpstat.us/400");
console.log("2");

// END WLIDE
0.00        *** Script Execution Start Time:  Thu Aug 15 17:15:56 2019 ***  
0.33        Start round 1 (1 of 1)  
0.34        1   
0.76        400 Bad request. Requested URL: https://httpstat.us/400. in main_agenda at line 15  
1.85        End round 1 (1 of 1)    
2.06        *** Script Execution End Time:  Thu Aug 15 17:15:58 2019 ***    
2.06        Test Failed: The number of errors is equal to or greater than 1.    

Solution

  • You should use wlHttp.ReportHttpErrors=false.

    Use document.wlStatusNumber to check the response.

    See example:

    function InitAgenda()
    {
    
    wlGlobals.GetFrames = false;
        wlGlobals.SaveSource = true;
        wlGlobals.SaveHeaders = true;
    }
    /***** WLIDE - ID:5 - JavaScript *****/
    
    wlHttp.ContentType = "application/json";
    
    console.log("1");
    wlHttp.ReportHttpErrors=false
    wlHttp.Get("https://httpstat.us/400");
    if (document.wlStatusNumber != 400) {
        WarningMessage("hmm, expected 400 but got " + document.wlStatusNumber + ", " + document.wlStatusLine)
    }
    console.log("2");