ATS : HTTP Operations - Working with the response

You should always carefully examine the response otherwise you will not be confident in the success of your HTTP call.

Additionally, often you will need to get data from the response in order to decide how to continue your test execution.

 


Explore the response

Every HTTP method returns a HttpResponse and here are some useful methods it has:

// get status code, for example "200"
int statusCode = response.getStatusCode();

// get status message, for example "SUCCESS"
String statusMessage = response.getStatusMessage();

// get received headers, you can iterate them and read their "name" and "value"
HttpHeader[] headers = response.getHeaders();

// get received body as a String
String body = response.getBodyAsString();

 


Verify the response

Every HTTP response can be verified by header, body, status code, status message.

ATS verify methods check if the condition is met, if not an exception is thrown and this fails the test with an appropriate error message.

// verify status code, for example "200"
response.verifyStatusCode(200);

// verify status message, for example "SUCCESS"
response.verifyStatusMessage("SUCCESS");

// verify received header, e.g. header name "Content-Type", with value "text/html"
response.verifyHeader( "Content-Type", "text/html" );

// verify part of response body, e.g. response body "Some simple page response"
response.verifyBodyContent("page");
 
// verify full body, e.g. response body "Some simple page response"
response.verifyBodyMatch("Some simple page response");

// verify response body by REGEX, e.g. response body "Some simple page response"
response.verifyBodyRegex(".*page\\D");

 


Back to parent page

Go to Table of Contents