`import io .restassured.RestAssured;
импортировать io.restassured.path.json.JsonPath;
импортировать статический io.restassured.RestAssured.;
импортировать статическую организацию .hamcrest.Matchers.;
import Files.Payload;
Основы общедоступного класса {
Код: Выделить всё
public static void main(String[] args) {
// TODO Auto-generated method stub
// Validate if Add place App is working as expected
// Validate if Add place App is working as expected -> Get place to validate if
// new address is present in response
// Given - all the input details
// When - submit the API- resource, https method
// Then - validated the response
RestAssured.baseURI = "https://rahulshettyacademy.com";
String response = given().log().all().queryParam("Key", "qaclick123").header("Content-Type", "application/json")
.body(Payload.AddPlace()).when().post("maps/api/place/add/json").then().assertThat().statusCode(200)
.body("scope", equalTo("APP")).header("Server", "Apache/2.4.52 (Ubuntu)").extract().response()
.asString();
System.out.println(response);
JsonPath js = new JsonPath(response); // for parsing Json
String PlaceId = js.getString("place_id");
System.out.println(PlaceId);
// Update Place
String NewAddress = "70 Summer walk, USA";
given().log().all().queryParam("Key", "qaclick123").header("Content-Type", "application/json")
.body("{\r\n" + "\"place_id\":\"" + PlaceId + "\",\r\n" + "\"address\":\"" + NewAddress + "\",\r\n"
+ "\"key\":\"qaclick123\"\r\n" + "}")
.when().put("maps/api/place/update/json").then().log().all().assertThat().statusCode(200)
.body("msg", equalTo("Address successfully updated"));
// Get Place
String getPlaceResponse = given().log().all().queryParam("place_id", PlaceId).queryParam("Key", "qaclick123")
.header("Content-Type", "application/json").when().get("maps/api/place/get/json").then().statusCode(200)
.log().all().assertThat().extract().response().asString();
JsonPath js1 = new JsonPath(getPlaceResponse); // for parsing Json
String ActualAddress = js1.getString("address");
System.out.println(ActualAddress);
}
`
полезная нагрузка
файлы пакета;
полезная нагрузка общедоступного класса {
Код: Выделить всё
public static String AddPlace()
{
return "{\r\n"
+ " \"location\": {\r\n"
+ " \"lat\": -38.383494,\r\n"
+ " \"lng\": 33.427362\r\n"
+ " },\r\n"
+ " \"accuracy\": 50,\r\n"
+ " \"name\": \"Frontline house\",\r\n"
+ " \"phone_number\": \"(+91) 983 893 3937\",\r\n"
+ " \"address\": \"29, side layout, cohen 09\",\r\n"
+ " \"types\": [\r\n"
+ " \"shoe park\",\r\n"
+ " \"shop\"\r\n"
+ " ],\r\n"
+ " \"website\": \"http://google.com\",\r\n"
+ " \"language\": \"French-IN\"\r\n"
+ "}";
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... n-document