Hello,
There are several API-REST request we use in our test.
We used them several times at hundred of differents tests cases.
Due to server instability, 1/1000 appr crashed with html error.
In prod those request have retry in those cases.
We want to relaunch only the request with the same parameter.
We’d like to reproduce this at OR request level, on verification tab (We want to avoid refactoring all).
RequestObject request = WSResponseManager.getInstance().getCurrentRequest()
ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()
String contentType = response.getHeaderFields().get('Content-Type').get(0)
//Check if response is HTML
if(contentType.contains('text/html')) {
//retry here
}
I would say, Katalon Studio offers no built-in feature of “retrying API Request”. You need to implement “retry” by your own code.
If you are willing, you can implement “retry”. For example, previously, there was a discussion originated by @mqamar, which looks quite similar to your case.
There I proposed an idea but @mqamar quit the discussion. Possibly @mqamar did not like my idea because it involved a lot of code changes for him. I am afraid, @geoffrey.doco might be disappointed as well.
@geoffrey.doco can study this. He should be able to develop a new Custom Keyword, which inherites the built-in SendRequestKeywrod class while he want to add the “retry” processing the sendRequest method:
for (max N times) {
WebServiceCommonHelper.checkRequestObject(request)
ResponseObject responseObject = WebServiceCommonHelper.sendRequest(request)
//Check if response is HTML
String contentType = responseObject.getHeaderFields().get('Content-Type').get(0)
if(!contentType.contains('text/html')) {
break
} else {
// log error, wait a while and retry sending request
}
}
...
return responseObject
Once @geoffrey.doco got his own Custom keyword “sendRequestWithRetry” keyword, he would want to edit his test cases to call “sendRequestWithRetry” instead of the built-in “sendRequest”.
To add more aggressive approach, Groovy’s Metaprogramming technique is applicable. Groovy allows you to rewrite sendRequest() method of com.kms.katalon.core.webservice.keyword.builting.SendRequestKeyword class dynamically at runtime. Once you could rewrite the implementation of the SendRequestKeyword#sendRequest() method so that it internally performs “retry when HTML is responded”, then @geoffrey.doco would be able to change the behavior of Test Cases just a bit of configurational code.
By the way, if you are using Katalon Studio v9.1 or newer version and you want to develop a Custom Keyword, you need to purchase an Enterprise license. The v9.0 and older versions, Custom Keyword remains available for the Free licensees.
As we have yet to see the OP of this thread (@geoffrey.doco) confirm whether or not the proposed solutions here work for him. We will assume that the issue has been solved and will proceed to close this thread up soon.