In the test case, I assigned the cookie var to global
request header contain the value
GlobalVariable.CloudCookies = CookiesActions.getCookieValue()
APIActions.verifyStatusCode(GlobalVariable.StatusCode[‘Created’], GlobalVariable.WishlistAPIs.get(1))
The getcookie method
public static void getCookieValue() {
WebUI.waitForPageLoad(5, FailureHandling.STOP_ON_FAILURE)
WebDriver driver = DriverFactory.getWebDriver()
WebUI.refresh()
// create a temp variable to store the cookies
String cookieString = ‘’
// get all the cookies
Set cookieCollection = driver.manage().getCookies()
// a list of the cookies we want to use in our API calls later (these will get copied) ** must match EXACTLY
def interestingCookies = [
‘CurrentLanguageId’,
‘SetContextLanguageCode’,
‘CurrentCurrencyId’,
‘SetContextPersonaIds’,
‘InsiteCacheId’,
‘acceptCookies’,
‘CurrentBillToId’,
‘CurrentShipToId’,
‘BillToIdShipToId’,
‘CurrentPickUpWarehouseId’,
‘CurrentFulfillmentMethod’,
‘.AspNet.ApplicationCookie’
]
// loop through each cookie and append COOKIENAME=COOKIEVALUE; to the temp variable
for (Cookie currentCookie : cookieCollection) {
if (interestingCookies.contains(currentCookie.getName())) {
cookieString += (((currentCookie.getName() + ‘=’) + currentCookie.getValue()) + '; ')
}
}
// print the cookies for debugging
println(cookieString)
GlobalVariable.CloudCookies=cookieString
// set the cookies to our global variable. This is the most important bit!
}
}
