Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(playwright): relaunch browser correctly with restart: 'session' in run-workers --by pool #5118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Copy link
Contributor

@Samuel-StO Samuel-StO commented Aug 28, 2025
edited
Loading

Description

This PR fixes a pool-mode–specific issue in the Playwright helper when restart: 'session' is enabled.

In run-workers --by pool, each test is executed via its own codecept.run() call. At the end of a test, _finishTest() triggers _stopBrowser(). However, _stopBrowser() left the helper’s internal state in an inconsistent condition (e.g. isRunning not reset, browserContext still referenced). On the subsequent test run, _beforeSuite() believed a browser was still active and did not relaunch it, leading to page is null / waitForURL errors.

This change ensures the helper’s state is fully reset when stopping the browser so that the next pool-assigned test relaunches cleanly.


Scope / Affected configurations

  • Affected: run-workers --by pool with Playwright helper configured as restart: 'session'.
  • Not affected: legacy batch mode (single codecept.run()), restart: false / 'context' (browser stays up), and 'browser' (browser restart is expected every test).

Environment where reproduced: CodeceptJS v3.7.5-beta.1 (Playwright helper).


Why this didn’t break before

In legacy batch mode, a worker received a batch of tests and executed them in a single codecept.run() call. _finishTest() ran only once at the end of the batch, so the browser lifecycle remained consistent and the issue was masked.

With pool mode, each test gets its own codecept.run(). _finishTest() is invoked after every test, and because _stopBrowser() did not fully reset helper state, the next codecept.run() incorrectly assumed a live browser and skipped relaunch.


Reproduction

Setup

  • Playwright helper with restart: 'session'
  • Execute with run-workers --by pool

In code actions

  1. Start workers in pool mode.
  2. First test runs.
  3. _finishTest() calls _stopBrowser() at end of test.
  4. Pool scheduler assigns a second test.
  5. Second test begins.

Observations

  • First test passes.
  • Second test does not open a new browser/context.
  • Steps fail with messages like:
    • page is null, returning
    • Cannot read properties of undefined (reading 'waitForURL')

Fix

Ensure _stopBrowser() fully resets Playwright helper state so that _beforeSuite() (or the next test’s setup) reliably relaunches the browser in pool mode with restart: 'session'. Concretely:

  • Set isRunning = false.
  • Close and then null out browserContext.
  • Close and then null out browser.

Result

  • With restart: 'session' in run-workers --by pool, each new test now relaunches a fresh browser/session as intended.
  • Pool mode runs multiple tests sequentially without page is null failures.
  • Legacy batch mode and other restart strategies remain unchanged.

Risk / Compatibility

Low risk. The change is limited to the Playwright helper’s teardown path and only impacts flows that stop the browser. Normal runs and other restart strategies keep their current behavior.


Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium
  • TestCafe

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

Copy link
Contributor Author

Issue caused by : #5089

Copy link
Collaborator

kobenguyent commented Aug 28, 2025
edited
Loading

@Samuel-StO thanks for the fix. Would you mind adding some tests for it? Like at the acceptance level to make sure everything work. https://github.com/codeceptjs/CodeceptJS/tree/3.x/test/acceptance

@kobenguyent kobenguyent merged commit 773ba14 into codeceptjs:3.x Aug 28, 2025
14 checks passed
@Samuel-StO Samuel-StO deleted the bugfix/pool-mode-imcopatibilty-with-context-restart branch August 28, 2025 13:53
Copilot AI pushed a commit that referenced this pull request Sep 1, 2025
... in `run-workers --by pool` (#5118)
* fix: Reset browser context and state on close
* test: add acceptance tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /