java - Multiple headers in Rest Assured does not work and respond with a 401 Unauthorized code -
need know if making mistake in passing headers in below code (is right way of passing multiple headers in rest assured?) exception followed in rest assured . header values passed works in jmeter , postman.
exception:
java.lang.assertionerror: 1 expectation failed. expected status code <200> doesn't match actual status code <401>.
code:
import org.junit.test; import com.jayway.restassured.*; import com.jayway.restassured.http.contenttype; import static org.hamcrest.matchers.*; import static com.jayway.restassured.restassured.*; public class apiresponse { @test public void response () { given(). header("id", "abc"). header("key", "nudvhdsfymnkdlozq"). header("conid", "xyz"). when(). get("testme/api/uk?id=dt44fr100731"). then(). //contenttype(contenttype.json). body("response.code", equalto("200")); } }
401 - unauthorized status result when don't pass authentication info rest service.
you can pass authentication follows:
given(). auth(). basic("userid","password"). header(). .... expect(). statuscode(200) log().iferror() ... you can find more authentication schemes supported rest-assured in given github link
Comments
Post a Comment