(test)
| 555 | } |
| 556 | |
| 557 | async _before(test) { |
| 558 | // Skip browser operations in dry-run mode (used by check command) |
| 559 | if (store.dryRun) { |
| 560 | this.currentRunningTest = test |
| 561 | return |
| 562 | } |
| 563 | |
| 564 | this.currentRunningTest = test |
| 565 | |
| 566 | // Reset failure tracking for each test to prevent false positives |
| 567 | this.hasCleanupError = false |
| 568 | this.testFailures = [] |
| 569 | |
| 570 | // Reset frame context to ensure clean state for each test |
| 571 | this.context = this.page |
| 572 | this.frame = null |
| 573 | this.contextLocator = null |
| 574 | |
| 575 | // Clear popup state to ensure clean state for each test |
| 576 | popupStore.clear() |
| 577 | |
| 578 | recorder.retry({ |
| 579 | retries: test?.opts?.conditionalRetries || 3, |
| 580 | when: err => { |
| 581 | if (!err || typeof err.message !== 'string') { |
| 582 | return false |
| 583 | } |
| 584 | // ignore context errors |
| 585 | return err.message.includes('context') |
| 586 | }, |
| 587 | }) |
| 588 | |
| 589 | // Start browser if needed (initial start or browser restart strategy) |
| 590 | if (!this.isRunning && !this.options.manualStart) await this._startBrowser() |
| 591 | else if (restartsBrowser() && !this.options.manualStart) { |
| 592 | // Browser restart strategy: start browser for each test |
| 593 | await this._startBrowser() |
| 594 | } |
| 595 | |
| 596 | this.isAuthenticated = false |
| 597 | if (this.isElectron) { |
| 598 | this.browserContext = this.browser.context() |
| 599 | } else if (this.playwrightOptions.userDataDir) { |
| 600 | this.browserContext = this.browser |
| 601 | } else { |
| 602 | const contextOptions = { |
| 603 | ignoreHTTPSErrors: this.options.ignoreHTTPSErrors, |
| 604 | acceptDownloads: true, |
| 605 | ...this.options.emulate, |
| 606 | } |
| 607 | if (this.options.basicAuth) { |
| 608 | contextOptions.httpCredentials = this.options.basicAuth |
| 609 | this.isAuthenticated = true |
| 610 | } |
| 611 | if (this.options.bypassCSP) contextOptions.bypassCSP = this.options.bypassCSP |
| 612 | if (this.options.recordVideo) contextOptions.recordVideo = this.options.recordVideo |
| 613 | if (this.options.recordHar) { |
| 614 | const harExt = this.options.recordHar.content && this.options.recordHar.content === 'attach' ? 'zip' : 'har' |
nothing calls this directly
no test coverage detected