简体   繁体   English

接收非 200 状态代码时,如何防止 WebLOAD wlHttp 模块中止回合?

[英]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.我最近的任务是在 WebLOAD 中工作以测试 API 的功能。 Alternatives to WebLOAD can't be used for the task due to the project's requirements.由于项目的要求,不能将 WebLOAD 的替代品用于该任务。

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.我负责编写的一些测试用例涉及提交格式错误的请求并确保返回 400 响应代码。 My problem is that every time a non-200 response is received, wlHttp throws an error in the console and aborts the current round.我的问题是每次收到非 200 响应时,wlHttp 都会在控制台中引发错误并中止当前回合。

I've tried surrounding the wlHttp.Get call with a try/catch but that didn't work.我试过用 try/catch 来包围wlHttp.Get调用,但这没有用。 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.任何帮助将不胜感激,从本文档来看,似乎应该可以在收到非 200 状态代码后继续。

Below is an MVP similar to the code I'm writing for my test cases.下面是一个 MVP,类似于我为我的测试用例编写的代码。 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.在控制台输出(在 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.    

You should use wlHttp.ReportHttpErrors=false .您应该使用wlHttp.ReportHttpErrors=false

Use document.wlStatusNumber to check the response.使用 document.wlStatusNumber 检查响应。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM