Search code examples
javaapirestautomationrest-assured

How to fetch the http status code when the response type defined is string instead of Respone


int statusCode = res.getStatusLine().getStatusCode();Please refer for code

Is there any way to cast string to Response to use the predefined method getStatusCode() else any other way to fetch the status code?


Solution

  • You can have both Response and String, for example.

    Response response = given().patch();
    int statusCode = response.statusCode();
    
    String res = response.asString();