Back to Course
Rest Assured

Extracting Status Code From Response Using Restassured

Why Extract the Status Code?

Sometimes a test needs to store the status code for further logic, rather than asserting on it directly within the chain.

Example

int statusCode = given()
    .when().get("/users/2")
    .then().extract().statusCode();

System.out.println(statusCode); // 200

Where This Is Useful

Useful for conditional logic in a test, such as retrying a request only if the status code indicates a temporary server issue.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course