How to get SoapUI XML request and XML response in java
I am using SoapUI API as part of an existing java project. The application must store the XML request and response in a specific report file. I wonder if it is possible to get these requests and responses through the API. The method calling TestCaseRunner looks like this:
protected void checkTestCase(TestCase testCase) {
TestCaseRunner tr = testCase.run(null, false);
for (TestStepResult tcr : tr.getResults()) {
String status = tcr.getStatus();
String time = tcr.getTimeTaken() + "ms";
/* How to get XML messages?
* String request =
* String response =
*/
}
}
+3
source to share
2 answers
Depending on exactly which test steps you have, they might be a MessageExchange instance. Passing TestStepResult to MessageExchange and calling getRequestContent / getResponseContent can do the trick.
String request = ((MessageExchange)tcr).getRequestContent();
String response = ((MessageExchange)tcr).getResponseContent();
+2
source to share
I used the following way to get the response from API CAll:
runner = testRunner.runTestStepByName("Your Test Case name");
// Here we take the response in ms of the API call
timeTaken = runner.response.timeTaken;
// here we get the HTTP response code.
responseCode = runner.getResponseHeaders()."#status#";
// here we get the response content
String response = runner.getResponseContent();
// here we get the API call endpoint -> in case you need to print it out.
String endPoint = runner.getEndpoint();
0
source to share