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

Method waitForCookie

lib/helper/Playwright.js:3773–3803  ·  view source on GitHub ↗

* {{> waitForCookie }}

(name, sec)

Source from the content-addressed store, hash-verified

3771 * {{> waitForCookie }}
3772 */
3773 async waitForCookie(name, sec) {
3774 // by default, we will retry 3 times
3775 let retries = 3
3776 const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout
3777
3778 if (sec) {
3779 retries = sec
3780 } else {
3781 retries = Math.ceil(waitTimeout / 1000) - 1
3782 }
3783
3784 return promiseRetry(
3785 async (retry, number) => {
3786 const _grabCookie = async name => {
3787 const cookies = await this.browserContext.cookies()
3788 const cookie = cookies.filter(c => c.name === name)
3789 if (cookie.length === 0) throw Error(`Cookie ${name} is not found after ${retries}s`)
3790 }
3791
3792 this.debugSection('Wait for cookie: ', name)
3793 if (number > 1) this.debugSection('Retrying... Attempt #', number)
3794
3795 try {
3796 await _grabCookie(name)
3797 } catch (e) {
3798 retry(e)
3799 }
3800 },
3801 { retries, maxTimeout: 1000 },
3802 )
3803 }
3804
3805 async _waitForAction() {
3806 return this.wait(this.options.waitForAction / 1000)

Callers

nothing calls this directly

Calls 1

retryFunction · 0.85

Tested by

no test coverage detected