I have a scenario where, Every time a cookie value will be 0 or 1 or Cookie will not be present
I wanted to refresh the page unless Cookie value is 0 or Cookie not present.
If cookie value is 1, Delete all the cookie and refresh the page and do the check again.
This has to happen till cookie value is 0 or Cookie itself is not present
Below script runs only once if cookie value is 1. How to make it run till cookie value is not 1 or cookie is not present in loop
log.step("Load Site from URL mentioned in Excel Sheet");
log.step("Load Site from URL mentioned in Excel Sheet");
$browser
.get(startingurl) //URL is given here
.then(function () {
log.info("Starting URL: " + startingurl);
}) //Access URL mentioned in the Excel Sheet
.then(function () {
$browser.sleep(PageLoadSleep3s);
let track = 0;
cookie = "test";
do {
console.log("Cookie:" + cookie);
return $browser
.manage()
.getCookie(cookie)
.then(function (text) {
if (text) {
console.log("Cookie Value is: " + JSON.stringify(text));
if (text.value != 1) {
track = 1;
} else {
return $browser
.manage()
.deleteAllCookies()
.then(function () {
log.info("Refresh the page");
return $browser.navigate().refresh();
});
}
} else {
console.log("Cookie Not found");
}
});
} while (track == 0);
});