setting content type in rest assured

后端 未结 8 1274
广开言路
广开言路 2021-01-07 21:53

I\'m trying to invoke a rest call using rest assured. My API accepts, \"application/json\" as content type and I need to set in the call. I set the content type

8条回答
  •  爱一瞬间的悲伤
    2021-01-07 22:34

    import io.restassured.RestAssured;
    import io.restassured.http.ContentType;
    
    import static org.hamcrest.Matchers.is;
    import org.testng.annotations.Test;
    import static io.restassured.RestAssured.given;
    
    public class googleMapsGetLocation {
        @Test
        public void getLocation() {
            RestAssured.baseURI = "https://maps.googleapis.com";
            given().param("location", "-33.8670522,151.1957362")
                .param("radius", "500")
                .param("key", "AIzaSyAONLkrlUKcoW-oYeQjUo44y5rpME9DV0k").when()
                .get("/maps/api/place/nearbysearch/json").then().assertThat()
                .statusCode(200).and().contentType(ContentType.JSON)
                .body("results[0].name", is("Sydney"));
        }
    }
    

提交回复
热议问题