Runs setup script and captures authentication state for reuse.
(
setupFn: SetupFunction,
timeout: number,
)
| 74 | |
| 75 | /** Runs setup script and captures authentication state for reuse. */ |
| 76 | async captureAuthState( |
| 77 | setupFn: SetupFunction, |
| 78 | timeout: number, |
| 79 | ): Promise<void> { |
| 80 | const browser = await this.launchBrowser(); |
| 81 | const context = await browser.newContext(); |
| 82 | const page = await context.newPage(); |
| 83 | |
| 84 | try { |
| 85 | page.setDefaultTimeout(timeout); |
| 86 | await runSetup(setupFn, page); |
| 87 | this.storageState = await context.storageState(); |
| 88 | logger.debug('Captured authentication state from setup script'); |
| 89 | } finally { |
| 90 | await page.close(); |
| 91 | await context.close(); |
| 92 | logger.debug('Closed setup context'); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** Closes the browser and clears authentication state. */ |
| 97 | async close(): Promise<void> { |
no test coverage detected