-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
Merged
kobenguyent
merged 2 commits into
codeceptjs:3.x
from
Samuel-StO:bugfix/pool-mode-imcopatibilty-with-context-restart
Aug 28, 2025
Merged
fix(playwright): relaunch browser correctly with restart: 'session'
in run-workers --by pool
#5118
kobenguyent
merged 2 commits into
codeceptjs:3.x
from
Samuel-StO:bugfix/pool-mode-imcopatibilty-with-context-restart
Aug 28, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Issue caused by : #5089
@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
@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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 owncodecept.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 topage 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
run-workers --by pool
with Playwright helper configured asrestart: 'session'
.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 nextcodecept.run()
incorrectly assumed a live browser and skipped relaunch.Reproduction
Setup
restart: 'session'
run-workers --by pool
In code actions
_finishTest()
calls_stopBrowser()
at end of test.Observations
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 withrestart: 'session'
. Concretely:isRunning = false
.browserContext
.browser
.Result
restart: 'session'
inrun-workers --by pool
, each new test now relaunches a fresh browser/session as intended.page is null
failures.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:
Applicable plugins:
Type of change
Checklist:
npm run docs
)npm run lint
)npm test
)