【问题标题】:How to prevent WebLOAD wlHttp module from aborting round when receiving non-200 status code?收到非200状态码时如何防止WebLOAD wlHttp模块中止?
【发布时间】:2019-08-15 22:33:44
【问题描述】:

我最近的任务是在 WebLOAD 中工作,以测试 API 的功能。由于项目的要求,该任务不能使用 WebLOAD 的替代方案。

我负责编写的一些测试用例涉及提交格式错误的请求并确保返回 400 响应代码。我的问题是每次收到非 200 响应时,wlHttp 都会在控制台中抛出错误并中止当前轮次。

我尝试使用 try/catch 来包围 wlHttp.Get 调用,但没有奏效。任何帮助将不胜感激,从this document 看来,在收到非 200 状态代码后似乎应该可以继续。

下面是一个类似于我为测试用例编写的代码的 MVP。在控制台输出(MVP 下方)中,您可以看到记录了“1”,但是在记录有关 400 的错误并且从未运行过 console.log("2") 后立即停止执行。

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.    

【问题讨论】:

    标签: javascript performance-testing functional-testing


    【解决方案1】:

    你应该使用wlHttp.ReportHttpErrors=false

    使用 document.wlStatusNumber 检查响应。

    查看示例:

    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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2011-05-20
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      相关资源
      最近更新 更多