CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

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

Open hxllv opened this issue 1 year ago • 1 comments

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'
}

hxllv avatar Nov 29 '24 10:11 hxllv

This may be related to my issue - still waiting for fix - where the tryTo() is throwing error in logs and the recorder falsy thinks it's a failure.

https://github.com/codeceptjs/CodeceptJS/issues/4516

The issue could be in the tryTo() module or how the recorder parse the errors. Still no fix as of today.

incoming-th avatar Dec 04 '24 04:12 incoming-th

tried the fix and output as following

***************************************
nodeInfo:  20.19.4
osInfo:  Linux 6.11 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
cpuInfo:  (4) x64 AMD EPYC 7763 64-Core Processor
chromeInfo:  139.0.7258.127
edgeInfo:  "N/A"
firefoxInfo:  undefined
safariInfo:  N/A
playwrightBrowsers:  "chromium: 140.0.7339.16, firefox: 141.0, webkit: 26.0"
If you need more detailed info, just run this: npx codeceptjs info
***************************************
CodeceptJS v3.7.4 #StandWithUkraine
Using test root "/tmp/verbose_test"
Helpers: CustomHelper
Plugins: screenshotOnFail

Test verbose output issue --
/tmp/verbose_test/verbose_issue_test.js
    [1]  Starting recording promises
    Timeouts: 
  test something
  Scenario()
    I am on page "https://codecept.io/quickstart/"
Going to https://codecept.io/quickstart/
    I see element ".doesntexist"
    [1] <tryTo>  Error (Non-Terminated) | Error: Element .doesntexist not found | err => { step.status = 'failed' step.endTime = +Da...
 › Unsuccessful try > Error: Element .doesntexist not found
    I fill field "#algolia-search-input", "codecept"
Filling #algolia-search-input with codecept
    I press key "Enter"
Pressing key Enter
    I see "CodeceptJS"
Checking for text: CodeceptJS
    I see checkbox is checked ".nocheckboxishere"
    [1]  Error (Non-Terminated) | Error: Checkbox .nocheckboxishere is not checked | err => { step.status = 'failed' step.endTime = +Da...
    [1] Error | Error: Checkbox .nocheckboxishere is not checked undefined...
    [1] <teardown>  Stopping recording promises
  ✖ FAILED in 11ms

    [2]  Starting recording promises

-- FAILURES:

  1) Test verbose output issue
       test something:
     
  Checkbox .nocheckboxishere is not checked
      at CustomHelper.seeCheckboxIsChecked (custom_helper.js:26:11)
      at HelperStep.run (/home/runner/work/CodeceptJS/CodeceptJS/lib/step/helper.js:28:49)
      at /home/runner/work/CodeceptJS/CodeceptJS/lib/step/record.js:45:26
  
  
  ◯ File: file:///tmp/verbose_test/verbose_issue_test.js
  
  ◯ Scenario Steps:
  ✖ I.seeCheckboxIsChecked(".nocheckboxishere") at Test.<anonymous> (./verbose_issue_test.js:12:5)
  ✔ I.see("CodeceptJS") at Test.<anonymous> (./verbose_issue_test.js:11:5)
  ✔ I.pressKey("Enter") at Test.<anonymous> (./verbose_issue_test.js:10:5)
  ✔ I.fillField("#algolia-search-input", "codecept") at Test.<anonymous> (./verbose_issue_test.js:9:5)
  ✔ I.amOnPage("https://codecept.io/quickstart/") at Test.<anonymous> (./verbose_issue_test.js:6:5)
  


  FAIL  | 0 passed, 1 failed   // 17ms

kobenguyent avatar Aug 22 '25 11:08 kobenguyent