What is the purpose of the given() method in RestAssured?

What is the purpose of the given() method in RestAssured?

A) To specify preconditions for the request
B) To send the request
C) To validate the response
D) To extract data from the response

Answer:

A) To specify preconditions for the request

Explanation:

The given() method in RestAssured is used to specify preconditions for the HTTP request, such as headers, query parameters, and body content. It sets up the request before it is sent.

For example:


import static io.restassured.RestAssured.*;

given().
    header("Authorization", "Bearer token").
    queryParam("key", "value").
    when().
    get("/api/resource").
    then().
    statusCode(200);

In this example, the given() method is used to specify a header and a query parameter for the GET request.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top