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

Method waitForCookie

lib/helper/Puppeteer.js:1911–1941  ·  view source on GitHub ↗

* {{> waitForCookie }}

(name, sec)

Source from the content-addressed store, hash-verified

1909 * {{> waitForCookie }}
1910 */
1911 async waitForCookie(name, sec) {
1912 // by default, we will retry 3 times
1913 let retries = 3
1914 const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout
1915
1916 if (sec) {
1917 retries = sec
1918 } else {
1919 retries = Math.ceil(waitTimeout / 1000) - 1
1920 }
1921
1922 return promiseRetry(
1923 async (retry, number) => {
1924 const _grabCookie = async name => {
1925 const cookies = await this.page.cookies()
1926 const cookie = cookies.filter(c => c.name === name)
1927 if (cookie.length === 0) throw Error(`Cookie ${name} is not found after ${retries}s`)
1928 }
1929
1930 this.debugSection('Wait for cookie: ', name)
1931 if (number > 1) this.debugSection('Retrying... Attempt #', number)
1932
1933 try {
1934 await _grabCookie(name)
1935 } catch (e) {
1936 retry(e)
1937 }
1938 },
1939 { retries, maxTimeout: 1000 },
1940 )
1941 }
1942
1943 /**
1944 * {{> clearCookie }}

Callers 1

testsFunction · 0.45

Calls 1

retryFunction · 0.85

Tested by

no test coverage detected