Skip to content

feat: add step.customMessage() to print a message above a failed step's error - #5819

Open
landon-medme wants to merge 2 commits into
codeceptjs:4.xfrom
landon-medme:feat/step-custom-message
Open

landon-medme wants to merge 2 commits into
codeceptjs:4.xfrom
landon-medme:feat/step-custom-message

Conversation

@landon-medme

@landon-medme landon-medme commented Nov 26, 2026 •

Copy link
Copy Markdown

Motivation/Description of the PR

  • A failing step reports only the helper's own error, e.g. element (#checkout) still not visible after 10 sec. That says what was missing but not what the test was trying to do. There was no way to attach a reason to a single step.

  • step.customMessage() adds one. Pass it as the step's last argument, or chain it on the step like .timeout():

    import step from 'codeceptjs/steps'
    
    I.waitForVisible('#checkout', 10, step.customMessage('Checkout never loaded after login'))
    I.see('Paid', '.order-status').customMessage('Order never reached the paid state')
    I.click('Pay', step.timeout(5).customMessage('Payment form did not submit'))

    When the step fails, the message is printed above the original error, which stays underneath, indented:

    Checkout never loaded after login
      element (#checkout) still not visible after 10 sec
    
  • It's a separate StepConfig field (customMessage), not a key in opts, so it combines with .opts(), .timeout() and .retry() in any order. It works for any step, not only assertions.

  • Assertion errors use the existing params.customMessage. This also fixes AssertionFailedError.inspect() printing customMessage twice when the template already includes {{customMessage}}, which all the built-in assertion templates do.

  • When a step fails, the steps already queued after it also get step.failed with the same error. The message is only added to a step that actually started, so a later step's message never ends up on an earlier step's error.

Applicable helpers:

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

The change is in the step recorder, so it applies to every helper.

Applicable plugins:

  • aiTrace
  • autoDelay
  • autoLogin
  • customLocator
  • pause
  • coverage
  • heal
  • retryFailedStep
  • screenshot
  • selenoid
  • stepTimeout
  • 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)

…'s error

Pass step.customMessage('...') as a step's last argument, or chain
.customMessage('...') on the step. When the step fails, the message is
printed above the original error, which is indented under it. Steps that
never ran because an earlier step failed keep the original error.
@landon-medme
landon-medme marked this pull request as ready for review November 26, 2026 13:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants