You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Working code: response = given().setBasePath("basePath").headers("key","value").body("{ }").when().post("");
Non-working code (In this case, I get 405 error code from the server which is returned when basePath is not configured properly): response = given().spec(setLogging()).spec(setConfig("basePath")).spec(addHeader("key", "value")).body("{ }").when().post("");
I'm configuring the baseUri in my TestNG Listener using RestAssured.baseURI = "baseUri" assignment in both above cases and it works correctly for the "working code" case. Below are the definition of the helper methods I've used in the non-working code above.
//helper method to enable HTTP method logging
public static RequestSpecification setLogging() {
return new RequestSpecBuilder().log(LogDetail.METHOD).build();
}
//helper methods to set baseURI/basePath
public static RequestSpecification setConfig(String basePath) {
Log.info("API endpoint under test: "+basePath);
return new RequestSpecBuilder().setBasePath(basePath).setContentType(ContentType.JSON).build();
}
//helper methods to add request headers
public static RequestSpecification addHeader(String key, String value) {
Log.info("Header: "+key+" = "+value);
return new RequestSpecBuilder().addHeader(key, value).build();
}
Working code:
response = given().setBasePath("basePath").headers("key","value").body("{ }").when().post("");
Non-working code (In this case, I get 405 error code from the server which is returned when
basePath
is not configured properly):response = given().spec(setLogging()).spec(setConfig("basePath")).spec(addHeader("key", "value")).body("{ }").when().post("");
I'm configuring the
baseUri
in my TestNG Listener usingRestAssured.baseURI = "baseUri"
assignment in both above cases and it works correctly for the "working code" case. Below are the definition of the helper methods I've used in the non-working code above.PS: Could this be related to bug #871 in any way?
The text was updated successfully, but these errors were encountered: