不显示“address_Components”的所有索引的所有“long_name”值。使用路径时:path("results[0].address_components[].long_name") 则测试用例失败。我想显示响应中给出的所有“long_name”值。请给我建议。
{
"results" : [
{
"address_components" : [
{
"long_name" : "Chicago",
"short_name" : "Chicago",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Cook County",
"short_name" : "Cook County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Chicago, IL, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.023131,
"lng" : -87.52366099999999
},
"southwest" : {
"lat" : 41.6443349,
"lng" : -87.9402669
}
},
"location" : {
"lat" : 41.8781136,
"lng" : -87.6297982
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.023131,
"lng" : -87.52404399999999
},
"southwest" : {
"lat" : 41.6443349,
"lng" : -87.9402669
}
}
},
"place_id" : "ChIJ7cv00DwsDogRAMDACa2m4K8",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
我正在使用硒(Maven TestNG):
@Test
public void test_08(){
String[] arrayList = {"chicago"};
for(int i=0; i<arrayList.length; i++){
Response resp = given().
parameter("address", arrayList[i]).
when().
get("http://maps.googleapis.com/maps/api/geocode/json");
Assert.assertEquals(resp.getStatusCode(), 200);
String respReport = resp.
then().
contentType(ContentType.JSON).
extract().
path("results[0].address_components[0].long_name");
System.out.println("Logn Name: "+respReport+);
}
}
输出:
登录名称:芝加哥
通过:test_08