Skip to content

Failed step in tryTo causes it to look like the source of failure in trace of steps #4619

@hxllv

Description

@hxllv

What are you trying to achieve?

We have a test that utilizes tryTo to resolve some flakiness with our app. During migration to playwright, test started failing and it looked like the reason for it was the step inside tryTo. However under close inspection that was not the reason that the test failed, it was instead something else later down the test.

What do you get instead?

I made this env separately to showcase the issue. The test fails because .nocheckboxishere was not found, but looking at the trace of scenario steps, it give the illusion that the check within tryTo for .doesntexist is the cause.

npm run codeceptjs

> [email protected] codeceptjs
> codeceptjs run --steps

CodeceptJS v3.6.7 #StandWithUkraine
Using test root "/Users/nacetavcer/ccjs"

tryTo --
  test something
    I am on page "https://codecept.io/quickstart/"
    I see element ".doesntexist"
false
    I fill field "#algolia-search-input", "codecept"
    I press key "Enter"
    I see "CodeceptJS"
    I see checkbox is checked ".nocheckboxishere"
  ✖ FAILED in 3271ms


-- FAILURES:

  1) tryTo
       test something:
     Checkable ".nocheckboxishere" was not found by text|CSS|XPath
      at new ElementNotFound (node_modules/codeceptjs/lib/helper/errors/ElementNotFound.js:15:11)
      at assertElementExists (node_modules/codeceptjs/lib/helper/Playwright.js:3742:11)
      at Playwright.proceedIsChecked (node_modules/codeceptjs/lib/helper/Playwright.js:3604:3)
  
  Scenario Steps:
  - I.seeElement(".doesntexist") at ./tryTo_test.js:5:42
  - I.amOnPage("https://codecept.io/quickstart/") at Test.<anonymous> (./tryTo_test.js:4:7)
  
  Artifacts:
  - screenshot: /Users/nacetavcer/ccjs/output/test_something.failed.png


  FAIL  | 0 passed, 1 failed   // 4s

Provide test source code if related

Feature('tryTo');

Scenario('test something', async ({ I }) => {
    I.amOnPage('https://codecept.io/quickstart/')
    const result = await tryTo(() => { I.seeElement('.doesntexist') })

    console.log(result)

    I.fillField('#algolia-search-input', 'codecept')
    I.pressKey('Enter')
    I.see('CodeceptJS')
    I.seeCheckboxIsChecked('.nocheckboxishere')
});

Details

  • CodeceptJS version: 3.6.7
  • NodeJS Version: 23.3.0
  • Operating System: macOS 15.1.1
  • Configuration file:
const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

/** @type {CodeceptJS.MainConfig} */
exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Playwright: {
      browser: 'chromium',
      url: 'http://google.com',
      show: true
    }
  },
  include: {
    I: './steps_file.js'
  },
  name: 'ccjs'
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions