MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / waitForCookie

Method waitForCookie

lib/helper/WebDriver.js:2093–2122  ·  view source on GitHub ↗

* {{> waitForCookie }}

(name, sec)

Source from the content-addressed store, hash-verified

2091 * {{> waitForCookie }}
2092 */
2093 async waitForCookie(name, sec) {
2094 // by default, we will retry 3 times
2095 let retries = 3
2096 const waitTimeout = sec || this.options.waitForTimeoutInSeconds
2097
2098 if (sec) {
2099 retries = sec
2100 } else {
2101 retries = waitTimeout - 1
2102 }
2103
2104 return promiseRetry(
2105 async (retry, number) => {
2106 const _grabCookie = async name => {
2107 const cookie = await this.browser.getCookies([name])
2108 if (cookie.length === 0) throw Error(`Cookie ${name} is not found after ${retries}s`)
2109 }
2110
2111 this.debugSection('Wait for cookie: ', name)
2112 if (number > 1) this.debugSection('Retrying... Attempt #', number)
2113
2114 try {
2115 await _grabCookie(name)
2116 } catch (e) {
2117 retry(e)
2118 }
2119 },
2120 { retries, maxTimeout: 1000 },
2121 )
2122 }
2123
2124 /**
2125 * Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt.

Callers

nothing calls this directly

Calls 1

retryFunction · 0.85

Tested by

no test coverage detected