How to validate a Restassured request through multiple Methods in Java?

Asked

Viewed 787 times

0

I am developing the Test Automation of a API using Rest Assured and Cucumber, mine Feature of Cucumber is like this:

@criarConta
        Esquema do Cenario: Criar uma conta valida
            Dado que realizo a chamada no <ambiente> da <api> informando <token_admin> e um email e <senha> novos
            Entao devera retornar <status code>

That is, I make the request in one step the validation in another. My class 'dataMap' (where the methods are like this):

public class dataMap extends tests {

    private Response response;
    private ValidatableResponse json;
    private RequestSpecification request;

        public void criarConta(String srtAmbiente, String srtAPI, String srtToken, String srtSenha) {

            String uriBase = srtAmbiente;
            String Api = srtAPI;

            int length = 15;
            String email = generateRandomEmail(length);
            System.out.println(email);
            Map<String, String> emailContent = new HashMap<String,String>();
            emailContent.put("email", email);
            Map<String, Object> postContent = new HashMap<String,Object>();
            postContent.put("customer", emailContent);
            postContent.put("password", srtSenha);

            request = RestAssured.given().contentType(ContentType.JSON)
                    .header("Authorization", "Bearer "+srtToken).with().body(postContent);

            response = request.when().post(uriBase+Api).prettyPeek();

        }

        public void responseCriarContaStatus (String srtStatusCode) {
            json = response.then().statusLine("HTTP/1.1 200 OK");

If I put the line json = response.then().statusLine("HTTP/1.1 200 OK"); in the top method "criarConta" it performs right, but as I am separating the validation it does not perform this second method. Can anyone help me? Thank you

  • Hi Cleicy. I may not be familiar with some particularity of your project, but I shouldn’t have one @Test in these test methods? How does the framework know which methods are for testing and which are not? In a normal Junit test, the methods with @Test are all called in the class.

  • Hello! I have another "Steps" class with has @Test pro Junit and the Cucumber Steps, and each step calls a method.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.