Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Session trace not cleaned up causing "tracing.stop" error in subsequent tests with Playwright

Closed
#5,456 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript, node.js, playwright
Domain
testing

Research direction

Start with the session() helper and Playwright trace lifecycle, using the reproduced session_test.js scenario and the configuration with trace and keepTraceForPassedTests enabled. Run both scenarios in sequence and follow cleanup after the session context closes. Done means the reproduction completes without a tracing.stop error and trace handling remains correct.

Written by the indexing model from the issue text.

Description

What are you trying to achieve?

I'm trying to run multiple test scenarios where the first scenario uses session() with Playwright helper and trace enabled. Both tests should pass without errors.

What do you get instead?

After the second test completes successfully, CodeceptJS throws an error:

Error: tracing.stop: Target page, context or browser has been closed

The session created in the first test is not properly cleaned up, and when the second test finishes, CodeceptJS attempts to save the trace for the old session that no longer exists.

Provide console output if related. Use --verbose mode for more details.

Session Bug Reproduction --
D:\projects\codeceptjs-bug\session_test.js
  First test with session
  Scenario()
    I am on page "/"
    user1: I am on page "/"
    user1: I see "Example Domain"
    I see "Example Domain"
  ✓ OK in 4197ms

  Second test - should fail with trace error
  Scenario()
    I am on page "/"
    I see "Example Domain"
  ✓ OK in 630ms

Error: tracing.stop: Target page, context or browser has been closed

  OK  | 2 passed   // 6s

Provide test source code if related

Feature('Session Bug Reproduction');

Scenario('First test with session', ({ I }) => {
  I.amOnPage('/');
  
  session('user1', () => {
    I.amOnPage('/');
    I.see('Example Domain');
  });
  
  I.see('Example Domain');
});

Scenario('Second test - should fail with trace error', ({ I }) => {
  I.amOnPage('/');
  I.see('Example Domain');
});
Details
  • CodeceptJS version: 3.7.6
  • NodeJS Version: v20+ (any recent version)
  • Operating System: Windows / Linux / macOS (reproduced on all)
  • Playwright version: 1.40.0
  • Configuration file:
exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Playwright: {
      url: 'https://example.com',
      show: false,
      browser: 'chromium',
      trace: true,
      keepTraceForPassedTests: true
    }
  },
  bootstrap: null,
  mocha: {},
  name: 'codeceptjs-session-bug'
}
Additional context

The issue appears when:

  • Multiple scenarios are run in sequence
  • Trace is enabled (especially with keepTraceForPassedTests: true)
  • One or more scenarios use session() helper

The session context is closed after the first scenario ends, but CodeceptJS still tries to stop tracing for it when the next scenario completes.

Minimal reproduction repository available if needed.

Dominant language
JavaScript
Stars
4.2k
Forks
756
Avg merge
2d 9h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from codeceptjs/CodeceptJS

All issues in codeceptjs/CodeceptJS

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.