Nullpointer when using Cucumber and Rest-Assured

Asked

Viewed 163 times

0

I’m performing an API test using Cucumber and Rest-Assured, but in the call I use Rest-Assured is being returned a NullPointer.

My Feature:

Scenario: Parâmetros não foram informados
Given A API de teste
When A requisição for realizada sem informar todos os parâmetros
Then A API deve retornar um status code 400
And uma mensagem de erro tratada

Part of my spec:

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

private String ENDPOINT_POST = "https://api-api/algo";
private String TOKEN = "teste";
private String TYPE = "application/json";

@Given("^A API de teste$")
public void a_API_de_teste() {
    request = request.with().contentType(TYPE).header("Authorization", TOKEN);
}

At the time of implementation of the @Given is being returned the following error:

java.lang.Nullpointerexception
at Steps.CenariosSteps.a_API(Cenariossteps.java:29)
at ?. Given The test API (/src/test/Resources/Features/cenarios.Feature:5)

I couldn’t get a clue what might be the cause, yet because the mistake doesn’t seem be popping all over.

I’m trying to follow the example of the site:

Rest-Assured with Cucumber: Using BDD for Web Services Automation - Angie Jones

Any suggestions?

1 answer

0

I solved my problem by changing it this way:

@Given("^A API de teste$")
public void a_API_de_teste() {
    request = RestAssured.with().contentType(TYPE).header("Authorization", TOKEN);
}

Browser other questions tagged

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