question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: onComplete Hook Provides an exit code of 1 When Test Suite Passes When Using Cucumber Tag Expression Due to Error in onRunnerStart hook of wdio-video-reporter

See original GitHub issue

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.0.13

Node.js Version

18.12.1

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [
    {
      maxInstances: 5,
      browserName: 'chrome',
      acceptInsecureCerts: true,
      'goog:chromeOptions': {
        prefs: {
          directory_upgrade: true,
          prompt_for_download: false,
          'download.default_directory': global.downloadDir,
        },
        args: [
          '--allow-insecure-localhost',
          '--disable-dev-shm-usage',
          '--enable-logging',
          '--headless',
          '--no-sandbox',
          '--use-fake-ui-for-media-stream',
          '--use-fake-device-for-media-stream',
          '--v=1',
          '--window-size=1200,900',
        ],
      },
    },
  ],

What happened?

I am running the latest wdio version and plugins with an ESM setup. I am running a limited set of tests with the following command: wdio run wdio.conf.ts --baseUrl https://localhost:8080 --cucumberOpts.tagExpression @organization My test suite passes but I get an exitCode of 1 in the onComplete hook which cause node to exit with an error: Screenshot 2022-12-22 at 7 21 08 PM

I am able to get the proper exit by checking the results and manually exiting the process with proper exit code as a workaround using the onComplete code below:

  onComplete(wdioExitCode, _config, _capabilities, results) {
    const generation = allure(['generate', 'allure-results', '--clean'])

    return new Promise<void>((resolve, reject) => {
      const reportError = new Error('Could not generate Allure report')

      const generationTimeout = setTimeout(() => {
        console.log('Allure generation timeout')
        return reject(reportError)
      }, 60 * 1000)

      generation.on('exit', async (allureExitCode: number) => {
        clearTimeout(generationTimeout)
        if (allureExitCode !== 0) {
          console.log(`Error in allure generation: exit code=${allureExitCode}`)
          return reject(reportError)
        }

        console.log(
          'Wdio Test Suite Exit Code: ',
          wdioExitCode,
          'Allure Exit Code: ',
          allureExitCode,
        )

        fs.readdirSync('./allure-results').forEach(fileName => {
          if (fileName.endsWith('.xml')) {
            console.log(`copying xml data file to allure-report: ${fileName}`)
            fs.copyFileSync(
              `./allure-results/${fileName}`,
              `./allure-report/data/${fileName}`,
            )
          }
        })
        // Do not change this console.log string, used for detection for kubectl cp in pipeline
        // Produce console output prior to sleep to allow time for copying.
        console.log('Allure Report Generation Success')
        await sleep(5 * 1000)

        console.log('# of Failed tests -> ', results.failed)
        if (results.failed > 0) {
          return reject(new Error(`Test Suite Has ${results.failed} Failures`))
        }
        return resolve(process.exit(0))
      })
    })
  },

I have also confirmed that all other hooks provide expected results and the cucumber hooks present passing results.

What is your expected behavior?

The onComplete exit code is 0 when the suite passes

How to reproduce the bug.

See above for output

Relevant log output

See above

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
christian-bromanncommented, Dec 24, 2022

Thanks for raising the PR. I merged and released the patch. I will go ahead and close this. Let’s create new issue for other items identified in this thread. Thanks for the contribution and merry Christmas!

0reactions
alexburkowskypolysigncommented, Dec 24, 2022

@christian-bromann as far as the fix in wdio-video-reporter its relatively simple. Just return early if there isnt a sessionId or found runnerInstance. I can put up a PR for that and tag you if that sounds reasonable.

The other option is to pass a hasTests property in the emit payload, but I think this is largely unnecessary. It would require some refactors in the callers of the _shutdown method and it would add another element that reporters would need to be aware of.

As for the logs issue, I will have to dig into that some more. The specific error that I would like to show up in the terminal is here https://github.com/webdriverio/webdriverio/blob/cfb83d28a3d28d17de8463d4e823078b7ac3c3ec/packages/wdio-local-runner/src/run.ts#L43. As you can see in my screenshot it is not present. Ill dig a bit after I address the wdio-video-reporter PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cucumber hook return 'skipped' not working #4567 - GitHub
2 ), hook return 'skipped' not skipping test. Tests that is supposed to be skipped continue to be executed. To Reproduce Sample feature...
Read more >
webdriverio/webdriverio - Gitter
this is my Hook file--->import {Before, BeforeAll, After, Status} from ... platform/architecture: darwin-arm64 error Command failed with exit code 1.
Read more >
Error in WDIO Chai/ Cucumber testsuite after updating ...
I'm working on Wdio-Chai-Cucumber based e2e-testsuite that ran fine ... @wdio/runner: TypeError: hooks.map is not a function at Object.
Read more >
How To Work With Cucumber Hooks - Axelerant
Hooks are blocks of code that run before or after each scenario in the Cucumber execution cycle. Here's how you can run them...
Read more >
wdio-light-reporter - npm
Start using wdio-light-reporter in your project by running `npm i ... add below code in the onComplete() hook in wdio conf file
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found