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!
}
Your test script can update GlobalVariables in memroy. But the Execution Profile files (e.g, “default”)
will be left unchanged. Katalon Studio does not provide any built-in way to update the Executio Profile files programatically.
If you want to, you need to develop some Groovy script that read and write the XML files for yourself.
katalon is not postman.
such have been allready explained in various topics.
katalon never writes back on the fly data for UI for GlobalVariables class
Check if the cookie exists
if (document.cookie.indexOf(“yourCookieName=”) !== -1) {
// Retrieve the cookie value
var cookieValue = document.cookie
.split(“; “)
.find(row => row.startsWith(“yourCookieName=”))
.split(”=”)[1];
// Assign the cookie value to a global variable
window.globalVariable = cookieValue;
}
In this example, we check if the cookie exists, retrieve its value, and then assign it to a global variable named `globalVariable". Click here for detail.