Ifrit
Ifrit

Reputation: 41

getting 302 while using a POST method in rest assured

I have written my test case as below and got the below error,

Error in Log:

FAILED: setpassword java.lang.AssertionError: 1 expectation failed. Expected status code <200> but was <302>.

Code:

@Test(enabled=true)

public void setpassword(){
    RequestSpecification requestSpecification= new Config().getRequestSpecification();
    RequestSpecification requestHeaders= new Config().getHeaders();

    Map<String,String> password = new HashMap<String, String>();
    password.put("password", "Password@2017");
        given().spec(requestSpecification).spec(requestHeaders).body(password).when().post("https://example.com/[email protected]/password").
    then().statusCode(200).log().all();


}

Upvotes: 1

Views: 4400

Answers (3)

Yasin Bekar
Yasin Bekar

Reputation: 147

Also, in my case, I had url with JWT token to test the lin/website. It brought to my attention that I did not use url + JWT as a complete link. I disregard the JWT, used only the link so it did not redirect the website.

Upvotes: 0

Yasin Bekar
Yasin Bekar

Reputation: 147

This helped me:

given().log().all().contentType("application/x-www-form-urlencoded; charset=UTF-8")
                .redirects().follow(false).redirects().max(100) 
                .queryParam()...

Upvotes: 0

Ifrit
Ifrit

Reputation: 41

i solved the issue. I was getting a 302 error because the api url was getting encoded. i used urlEncodingEnabled(false) and it solved the issue.

Upvotes: 2

Related Questions