java.lang.Object
net.serenitybdd.screenplay.playwright.questions.api.LastAPIResponse

public class LastAPIResponse extends Object
Query information about the most recent API response.

This question is used after an APIRequest interaction to retrieve details about the API response.

Sample usage:

     // Make an API request
     actor.attemptsTo(APIRequest.get("/api/users"));

     // Query the response
     int status = actor.asksFor(LastAPIResponse.statusCode());
     String body = actor.asksFor(LastAPIResponse.body());
     boolean ok = actor.asksFor(LastAPIResponse.ok());

     // Parse JSON response
     Map<String, Object> json = actor.asksFor(LastAPIResponse.jsonBody());
     List<Map<String, Object>> list = actor.asksFor(LastAPIResponse.jsonBodyAsList());

     // Get specific header
     String contentType = actor.asksFor(LastAPIResponse.header("Content-Type"));
     Map<String, String> allHeaders = actor.asksFor(LastAPIResponse.headers());

     // Get URL and status text
     String url = actor.asksFor(LastAPIResponse.url());
     String statusText = actor.asksFor(LastAPIResponse.statusText());
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.serenitybdd.screenplay.Question<String>
    Get the response body as a string.
    static net.serenitybdd.screenplay.Question<byte[]>
    Get the response body as bytes.
    static net.serenitybdd.screenplay.Question<String>
    header(String headerName)
    Get a specific header value from the response.
    static net.serenitybdd.screenplay.Question<Map<String,String>>
    Get all headers from the response.
    static net.serenitybdd.screenplay.Question<Map<String,Object>>
    Get the response body parsed as a JSON object (Map).
    static net.serenitybdd.screenplay.Question<List<Map<String,Object>>>
    Get the response body parsed as a JSON array (List of Maps).
    static net.serenitybdd.screenplay.Question<Boolean>
    ok()
    Check if the response was successful (status 200-299).
    static net.serenitybdd.screenplay.Question<com.microsoft.playwright.APIResponse>
    Get the raw APIResponse object for advanced operations.
    static net.serenitybdd.screenplay.Question<Integer>
    Get the HTTP status code of the response.
    static net.serenitybdd.screenplay.Question<String>
    Get the HTTP status text of the response.
    static net.serenitybdd.screenplay.Question<String>
    url()
    Get the final URL after any redirects.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • statusCode

      public static net.serenitybdd.screenplay.Question<Integer> statusCode()
      Get the HTTP status code of the response.
    • ok

      public static net.serenitybdd.screenplay.Question<Boolean> ok()
      Check if the response was successful (status 200-299).
    • statusText

      public static net.serenitybdd.screenplay.Question<String> statusText()
      Get the HTTP status text of the response.
    • body

      public static net.serenitybdd.screenplay.Question<String> body()
      Get the response body as a string.
    • bodyAsBytes

      public static net.serenitybdd.screenplay.Question<byte[]> bodyAsBytes()
      Get the response body as bytes.
    • jsonBody

      public static net.serenitybdd.screenplay.Question<Map<String,Object>> jsonBody()
      Get the response body parsed as a JSON object (Map).
    • jsonBodyAsList

      public static net.serenitybdd.screenplay.Question<List<Map<String,Object>>> jsonBodyAsList()
      Get the response body parsed as a JSON array (List of Maps).
    • header

      public static net.serenitybdd.screenplay.Question<String> header(String headerName)
      Get a specific header value from the response.
      Parameters:
      headerName - The name of the header (case-insensitive)
    • headers

      public static net.serenitybdd.screenplay.Question<Map<String,String>> headers()
      Get all headers from the response.
    • url

      public static net.serenitybdd.screenplay.Question<String> url()
      Get the final URL after any redirects.
    • response

      public static net.serenitybdd.screenplay.Question<com.microsoft.playwright.APIResponse> response()
      Get the raw APIResponse object for advanced operations.