放心:发布请求返回错误"The JSON input text should neither be null nor empty."



我是REST Api测试的新手。我正在开始Rest Assured for Rest Api测试,我在这方面有问题。以下是不断返回上述错误的代码

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import files.resources;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
public class Basics3 {
Properties prop = new Properties();
@BeforeTest
public void getData() throws IOException{
FileInputStream fis = new FileInputStream("C:\Users\boma.dagogo\Desktop\BOMA DAGOGO\eclipse-workspace\DemoProject\src\files\env.properties");
prop.load(fis);
//prop.get("HOST");
}
@Test
public void addandDeletePlace() {
String b = "{rn" +
"    "location":{rn" +
"        "lat" : -38.383494,rn" +
"        "lng" : 33.427362rn" +
"    },rn" +
"    "accuracy":50,rn" +
"    "name":"Frontline house",rn" +
"    "phone_number":"(+91) 983 893 3937",rn" +
"    "address" : "29, side layout, cohen 09",rn" +
"    "types": ["shoe park","shop"],rn" +
"    "website" : "http://google.com",rn" +
"    "language" : "French-IN"rn" +
"}";
RestAssured.baseURI = prop.getProperty("HOST");
Response res = given().
queryParam("key", " qaclick123").
body(b).
when().
post(resources.placePostData()).
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().
body("status", equalTo("OK")).
extract().response();
//Task 2: Grab the place_id from the response
String responseString = res.asString();
System.out.println(responseString);
JsonPath js = new JsonPath(responseString);
js.get("place_id");
String place_id = js.get("place_id");
System.out.println(place_id);
//Task 3: Place this place_id in the Delete request
given().
queryParam("key", prop.getProperty("KEY")).
body("{" +
""place_id":"" + place_id + """ +
"}").
when().
post("/maps/api/place/delete/json").
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().
body("status", equalTo("OK"));
}
}

字符串b中有错误。

只需按如下方式替换代码,然后重新运行:

String b = "{" +
""location":{" +
""lat" : -38.383494," +
""lng" : 33.427362" +
"}," +
""accuracy":50," +
""name":"Frontline house"," +
""phone_number":"(+91) 983 893 3937"," +
""address" : "29, side layout, cohen 09"," +
""types": ["shoe park","shop"]," +
""website" : "http://google.com"," +
""language" : "French-IN"" +
"}";

相关内容

  • 没有找到相关文章

最新更新