0
votes

I'm having this errors for all of my test cases. Please, help to find out what's wrong? I'm new to testing, so sorry if it's a silly question.

java.lang.AssertionError: 1 expectation failed. Expected status code <200> doesn't match actual status code <301>.

@Test (priority=1)
public static void authSuccess(){
    String id = "xxxxxxxxxx";
    given().
            param("id",id).
            when().
            post("/auth").
            then().
            statusCode(200).
            body("content.id", equalTo(id));
}

@Test (priority=2)
public static void authFail(){
    String id = "xxxxxxxxxx";
    given().
            param("id", id).
            when().
            post("/auth").
            then().
            statusCode(400).
            body("errors[0]", equalTo("Incorrect ID"));
}
1
You should check the HTTP error code description: en.m.wikipedia.org/wiki/HTTP_301 This one means that the URL you are POSTing to was moved to another location. Together with 301 server may provide the header specifying where it was moved. But first of all check that you are making calls to correct location. You are specifying relative location. Does your test know the base path? Is the application you test running? - Aleh Maksimovich
Try /aut/index.hml or something like that, as 301 MOVED PERMANENTLY indicates a redirection because of the path. Manually calling the URL one can request the page info. - Joop Eggen

1 Answers

1
votes

Hope you have tested in Postman/SoapUI before attempting into automation tests.

And you got 200 in postman as well.

Couple of pointers

  1. Check you are using same methods eg., get/post.
  2. Double check the endpoints you are using
  3. Make sure your headers and parameters are right between rest assured and postman.

Hope this helps out!