How to store id generated by post rest assured

Viewed 15

I'm trying to get the id generated when I make the post and use it in the future (maybe when testing the delete), but I'm not getting it.

My method that tests POST:

@Test
    public void givenData_WhenPost_Then200() throws Exception {

         String path = given()
            .body("{\r\n"
                + "    \"nome\":\"teste\",\r\n"
                + "    \"valor\": 2.5\r\n"
                + "}")
            .contentType(ContentType.JSON)
            .when()
            .post("/acessorios")
            .then()
            .log().all()
            .assertThat()
            .statusCode(200).extract().jsonPath().getString("nome");
         
         System.out.println(path);
        

    }

This code returns:

Failed to parse the JSON document.

And at last: is possible to use the id generate in others methods even its not global?

0 Answers
Related