Share Cookies between Step definitions of RestAssured Cucumber Example

BDD, Microservices
Recently I had to provide a framework to test a bunch of APIs in Cucumber RestAssured which has a login step definition. The login returned a set of cookies which should be used in subsequent requests. My first instinct was to use getDetailedCookies() and pass the cookies on to subsequent requests and set it using cookies(detailedCookies) method. But unfortunately there were cookies missing in the returned Cookies and subsequent API test requests failed. //Authentication Step definition String body="userId=1212&&password=232323"; String url = "http://mywebsitelogin.com"; Cookies detailedCookies =RestAssured.given().body(body).post(url).andReturn().getDetailedCookies(); return detailedCookies; //Actual API request RestAssured.given().cookies(detailedCookies).body(body).post(url); Finally CookieFilter came to rescue. The CookieFilter object will be filled with cookies and you can use it in other step definitions. Pretty simple but works like a charm. //Authentication Step CookieFilter filter = new CookieFilter(); String body="userId=1212&&password=232323"; String…
Read More