Rest-assured. Is it possible to extract value from request json?

前端 未结 5 911
死守一世寂寞
死守一世寂寞 2020-12-24 00:36

I\'m getting response this way:

Response response = expect().statusCode(200).given().body(requestBody).contentType(\"application/json\")
.when().post(\"/admi         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 01:30

    You can also do like this if you're only interested in extracting the "user_id":

    String userId = 
    given().
            contentType("application/json").
            body(requestBody).
    when().
            post("/admin").
    then().
            statusCode(200).
    extract().
            path("user_id");
    

    In its simplest form it looks like this:

    String userId = get("/person").path("person.userId");
    

提交回复
热议问题