fix(playwright): relaunch browser correctly with restart: 'session' in run-workers --by pool
          #5118
        
          
      
  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.
  
    
  
    
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.isRunningnot reset,browserContextstill referenced). On the subsequent test run,_beforeSuite()believed a browser was still active and did not relaunch it, leading topage is null/waitForURLerrors.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 poolwith 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 poolIn code actions
_finishTest()calls_stopBrowser()at end of test.Observations
page is null, returningCannot 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 nullfailures.restartstrategies 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)