API Testing With Rest Assured
API Testing With Rest Assured
Prerequisites:
Apiurl : api.openweathermap.org/data/2.5/weather?q=London
1. given().header(“Authorization”,
Key).contentType(“application/json”).when.get(apiurl).then.assert
That().statuscode(200);
Assert.assertEquals(response, 200);
Validate Json Data: method 1
String actual =
response.then().contentType(ContentType.JSON).extract().path(“weather.
description ");
1. given().when().get(apiurl).then().body(“Title”,
equalTo(“Selenium”).body(“language”,
equalTo(“Java”).statuscode(200);
2.
given().when().get(apiurl).then().assertThat().body(constainsStrin
g(“Selenium”);
Post Request: Methd 1
response.then().assertThat.statuscode(201);
Post Request: Method 2
requestSpec.post(APIUrl).getStatusCode();
Post: method 3
String message =
response.then().body()containsString(“Success”);
1. given().auth().basic(username, password).
2. given().header(“Authentication”, Key)