我正在尝试使用以下内容进行验证,但收到错误“ null”。当我尝试获取位置时,我无法前往“纬度”位置:-33.8585416。
{
"html_attributions": [],
"results": [
{
"geometry": {
"location": {
"lat": -33.8585416,
"lng": 151.2100441
},
我在Java中有以下脚本:
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import static org.hamcrest.Matchers.equalTo;
import static io.restassured.RestAssured.given;
public class BasicAPI {
@Test
public void nearByApi(){
RestAssured.baseURI= "https://maps.googleapis.com";
given().
param("location","-33.8670522,151.1957362").
param("radius","1500").
param("key","AIzaSyAPKUY3YgFBlyyQxjh9q9RQ5cDFdDjqlz4").
when().
get("/maps/api/place/nearbysearch/json").
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().
body("results[0].geometry.location.lat",equalTo("-33.8670522"));
}
}
继续出现以下错误:
[TestNG] Running:
C:\Users\PC1\AppData\Local\Temp\testng-eclipse-1596052068\testng-customsuite.xml
[Utils] Attempting to create C:\SampleFramworkFiles\DemoApi\test-output\Default suite\Default test.xml
[Utils] Directory C:\SampleFramworkFiles\DemoApi\test-output\Default suite exists: true
FAILED: nearByApi
java.lang.AssertionError: 1 expectation failed.
JSON path results[0].geometry.location.lat doesn't match.
Expected: -33.8670522
Actual: null