Hi,
I want to log the requests and responses in my api testing project.
I can print the responses to the log but cant get the requests.
RequestObject request = WSResponseManager.getInstance().getCurrentRequest()
KeywordUtil.logInfo(request.getBodyContent())
I also tried to access the har object from the test case, no success there…
Hi @daniel.andargie,
You can not use WSResponseManager.getInstance().getCurrentRequest() from the test case script. It can only be used in verification script of web service request object.
Regards.
I know, I do it on the verification script and I still get null.
Didn’t quite understand why I need to get the request from the WSResposeManager, isn’t there a WSRequestManager???
Can you paste the log here?
Hi @daniel.andargie,
When you call request.getBodyContent(), it will return a HttpBodyContent instance. Therefore, logging that instance will just give you the class name of that instance. To get the content, please construct an outputstream and use the method writeTo(outputstream) of HttpBodyContent.
Regards.
like that? I still get an empty string
Hi @daniel.andargie,
Maybe it’s because you have an empty request body content. Please check your request again.
Regards.
1 Like
You’re right, I thought it contains the header details.
now im trying to obtain the info from - request.getHttpHeaderProperties()
hi, @huynguyen I have a question maybe you can help me.
13:33:33.427 [main] INFO com.kms.katalon.core.main.WSVerificationExecutor - START Verification
13:33:33.846 [main] DEBUG testcase. - 1: request = getInstance().getCurrentRequest()
13:33:33.882 [main] WARN com.kms.katalon.core.testobject.ObjectRepository - Cannot find test object with id ‘null’ because of ‘org.dom4j.DocumentException: null\null.rs (ϵͳ�Ҳ���ָ����·����) Nested exception: null\null.rs (ϵͳ�Ҳ���ָ����·����)’
these is log ,request returns null , i don’t how to solve this problem
please help me
Hi @lxc775210,
Please share your request file (.rs file) for further investigation.
<?xml version="1.0" encoding="UTF-8"?>
aa
patList
63277b8d-e5ef-47c7-969c-1cb276639ded
BASIC
false
-1
true
{
"text": "{\n\"usId\":\"${usId}\",\n\"pltType\":\"app\",\n\"moduleCode\":\"OL_CONS\"\n}",
"contentType": "application/json",
"charset": "UTF-8"
}
text
false
equals
Content-Type
Main
application/json
false
equals
unicode
Main
${pat_unicode}
false
equals
client_id
Main
${pat_client_id}
false
equals
access_token
Main
yLsF0KT6JdU9qyvzZ51ovhYwA0CCtjThnShV0CWGzWj4BfMxiiHRQEU9PIg_MiGvlQ-rx7as_AQLWvEvkbNh9vM4yhpRReLfbQ8qUsypO-LxVy5GdAsZbn7YdOZgxDj3Xoas3L1txj_733PqMqMeGiQ
7.7.2
-1
5.4.1
POST
${yunuat}/hsyt-yun-restapi/r/${yunId}/80040/110
RESTful
-1
true
GlobalVariable.yunuat
3ae3b9b2-2d43-46b9-8ced-0ccf971e1536
false
yunuat
GlobalVariable.yunId
58cae1bc-54bb-4e08-8643-907e25470f69
false
yunId
GlobalVariable.pat_unicode
d4b9f10e-920a-4987-82a3-8b2610d05ff7
false
pat_unicode
GlobalVariable.pat_client_id
12563dfa-506b-470c-91f5-40897a25783f
false
pat_client_id
findTestData('testData/patToken').getValue(3, 1)
3f3bd6f8-0c57-4b61-b93e-0d75b2993ec7
false
usId
import static org.assertj.core.api.Assertions.*
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webservice.verification.WSResponseManager
import groovy.json.JsonSlurper
import internal.GlobalVariable as GlobalVariable
RequestObject request = WSResponseManager.getInstance().getCurrentRequest()
ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()
def jsonSlurper = new JsonSlurper()
def jsonResponse = jsonSlurper.parseText(response.getResponseText())
def patId = jsonResponse.data[0].patId.toString()
File file=new File("Data Files/testData/patID.csv");
BufferedWriter out=new BufferedWriter(new FileWriter(file))
out.write(patId);
out.flush();
out.close();
WS.verifyElementPropertyValue(response, ‘result’, true)
this is my .rs file’s content , Thank you very much for your reply
Hi @lxc775210,
Please attach the file, not copy and paste its content.