Yanilo
Yanilo

Reputation: 33

How to get SoapUI request and response XML in java

I'm using the SoapUI API as part of an existing java project. The application should save the request and response XML in an specific report file. I wonder if it's possible to get those requests and responses via the API. The method invoking the 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 = 
         */
    }
}

Upvotes: 3

Views: 6057

Answers (2)

Rami Sharaiyri
Rami Sharaiyri

Reputation: 546

I have used the following way to get the response from the API CAll performed:

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

Upvotes: -1

Joel Jonsson
Joel Jonsson

Reputation: 800

Depending on exactly what kind of test steps you have they might be an instance of a MessageExchange. Casting the TestStepResult to a MessageExchange and calling getRequestContent / getResponseContent might do the trick.

String request = ((MessageExchange)tcr).getRequestContent();
String response = ((MessageExchange)tcr).getResponseContent();

Upvotes: 3

Related Questions