Rest API自动化:断言不适用于google place API

Rest API自动化:断言不适用于google place API,rest,soap,automation,rest-assured,rest-assured-jsonpath,Rest,Soap,Automation,Rest Assured,Rest Assured Jsonpath,//下面提到的代码不适用于GoogleAPI中的断言 import io.restassured.RestAssured; import io.restassured.http.ContentType; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.equalTo; public class Base { public static void main(String[] a

//下面提到的代码不适用于GoogleAPI中的断言

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class Base {

public static void main(String[] args) {
    //URL --> End Point --> BaseURL/Resources/Format?Parameters
    // BaseURL or Host
    RestAssured.baseURI = "https://maps.googleapis.com";
    given().
            param("location","33.8670522,151.1957362").
            param("radius","500").
            param("key","AIzaSyDahQkqdxmUihrC0_3Gi7hRBZQWDrV1xI0").
            when().
            get("/maps/api/place/nearbysearch/json").
            then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().
            body("results[0].geometry.location.lat", equalTo("-33.8710748"));            
}
}
下面是我得到的错误: java.lang.AssertionError:1预期失败。 JSON路径结果[0]。geometry.location.lat不匹配。 预计:-33.8710748 实际值:空

还可以找到原始响应:


看起来,给定的代码是正确的,只是我希望所有适用的头都被提及,并且可能不会从状态代码为200的API中检索到有效的响应。出于调试目的,请提取响应并存储在一个变量中

请检查下面的调试

   public static void main(String[] args) {
    //URL --> End Point --> BaseURL/Resources/Format?Parameters
    // BaseURL or Host
    RestAssured.baseURI = "https://maps.googleapis.com";
    String result=given().
            param("location","33.8670522,151.1957362").
            param("radius","500").
            param("key","AIzaSyDahQkqdxmUihrC0_3Gi7hRBZQWDrV1xI0").
            when().
            get("/maps/api/place/nearbysearch/json").
            then().assertThat().statusCode(200).extract().asString();;

    System.out.println(" API Response :"+ result);
}

看起来只有JSON路径是正确的。您是否得到了有效的回复?我不理解您的回复,请详细说明,因为我是这个API测试的新手。在eclipse中,实际结果为null。我希望所有请求的查询参数都是正确的。因此,请先提取响应,然后在答案中添加示例。可能存在有效的故障