Skip to content

fix Cucumber retries collapsing into single Allure result#15180

Open
mccmrunal wants to merge 1 commit intomainfrom
fix/15177-allure-cucumber-retries
Open

fix Cucumber retries collapsing into single Allure result#15180
mccmrunal wants to merge 1 commit intomainfrom
fix/15177-allure-cucumber-retries

Conversation

@mccmrunal
Copy link
Copy Markdown
Contributor

@mccmrunal mccmrunal commented Apr 4, 2026

Closes #15177

Proposed changes

This commit fixes retry handling by gracefully isolating and terminating the aborted first attempt rather than letting it bleed into the second.

In onSuiteRetry, we now accurately deduce the status of the initial attempt, forcibly terminate it with a "retried" tag, and start a fresh Allure test for the next attempt

In onTestStart, I have implemented scenario collision detection to identify orphaned attempts (caused by scenarioLevelReporter), terminating them natively as FAILED before initializing Attempt #2.

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Reviewers: @webdriverio/project-committers

Copilot AI review requested due to automatic review settings April 4, 2026 10:49
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 4, 2026

Open in StackBlitz

create-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/create-wdio@15180

eslint-plugin-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@15180

@wdio/allure-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@15180

@wdio/appium-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@15180

@wdio/browser-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@15180

@wdio/browserstack-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@15180

@wdio/cli

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@15180

@wdio/concise-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@15180

@wdio/config

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@15180

@wdio/cucumber-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@15180

@wdio/dot-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@15180

@wdio/firefox-profile-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@15180

@wdio/globals

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@15180

@wdio/jasmine-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@15180

@wdio/json-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@15180

@wdio/junit-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@15180

@wdio/lighthouse-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@15180

@wdio/local-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@15180

@wdio/logger

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@15180

@wdio/mocha-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@15180

@wdio/protocols

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@15180

@wdio/repl

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@15180

@wdio/reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@15180

@wdio/runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@15180

@wdio/sauce-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@15180

@wdio/shared-store-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@15180

@wdio/smoke-test-cjs-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@15180

@wdio/smoke-test-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@15180

@wdio/smoke-test-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@15180

@wdio/spec-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@15180

@wdio/static-server-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@15180

@wdio/sumologic-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@15180

@wdio/testingbot-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@15180

@wdio/types

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@15180

@wdio/utils

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@15180

@wdio/webdriver-mock-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@15180

@wdio/xvfb

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/xvfb@15180

webdriver

npm i https://pkg.pr.new/webdriverio/webdriverio/webdriver@15180

webdriverio

npm i https://pkg.pr.new/webdriverio/webdriverio@15180

commit: 4d50c9c

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes how Cucumber scenario retries are represented in Allure by ensuring each attempt becomes its own Allure test result (instead of multiple attempts collapsing into a single result).

Changes:

  • Implemented onSuiteRetry logic to close attempt #1 with a retried tag and immediately start a fresh Allure test for attempt #2.
  • Added onTestStart “scenario collision” handling for scenarioLevelReporter to close orphaned/pending attempts before starting the next attempt.
  • Added/extended Cucumber retry regression tests for both default mode and scenarioLevelReporter mode.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/wdio-allure-reporter/src/reporter.ts Adds retry handling to end the first attempt and start a new Allure test; adds scenario-level retry collision detection.
packages/wdio-allure-reporter/tests/cucumber.suite.test.ts Adds regression tests asserting separate Allure results per retry attempt and correct retry tagging/historyId behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +661 to +670
const suiteChildren = [...(suite.tests || []), ...(suite.hooks || [])]
const isSkipped =
suiteChildren.length > 0 &&
(suite.tests || []).every((t: TestStats) => [AllureStatusEnum.SKIPPED].includes(t.state as AllureStatus)) &&
(suite.hooks || []).every((h: HookStats) => [AllureStatusEnum.PASSED, AllureStatusEnum.SKIPPED].includes(h.state as AllureStatus))
const failed = suiteChildren.find((i) => i.state === AllureStatusEnum.FAILED)
const status = isSkipped
? AllureStatusEnum.SKIPPED
: failed ? getTestStatus(failed) : AllureStatusEnum.FAILED
const error = failed ? getErrorFromFailedTest(failed) : undefined
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSuiteRetry tries to infer the first attempt's status/error from suite.tests/suite.hooks, but in the real WDIO event flow the @wdio/reporter listener calls suiteStat.retry() before invoking onSuiteRetry, which clears these arrays (see packages/wdio-reporter/src/index.ts:102-106 and packages/wdio-reporter/src/stats/suite.ts:64-69). This means suiteChildren will typically be empty here and statusDetails will never be populated. Consider persisting the last-known scenario failure details in the reporter state (e.g. when step/hook ends) or changing the integration point so onSuiteRetry receives the pre-cleared suite stats.

Copilot uses AI. Check for mistakes.
Comment on lines +681 to +694
// Open a fresh Allure test for the retry attempt.
// Sharing the same historyId is intentional: Allure uses it to group
// separate result files as retry attempts of the same scenario.
this._consoleOutput = ''
this._startTest({ name: suite.title, start: Date.now() })
this._currentLeafTitleByCid.set(cid, suite.title)
const fullTitleForHash = this._mochaFullTitle(cid, suite.title)
this._emitHistoryIdsFrom(fullTitleForHash)

const fullName = toFullName(this._pkgByCid.get(cid)!, fullTitleForHash)
this._pushRuntimeMessage({ type: 'allure:test:info', data: { fullName, fullTitle: fullTitleForHash } })

this._emitBaseLabels(cid)

Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry attempt initialization here largely duplicates the suite.type === 'scenario' branch in onSuiteStart, but it currently omits the applyTestPlanLabel(...) call and the _decideCucumberSkip/_tpSkipByCid skip handling present in onSuiteStart (around packages/wdio-allure-reporter/src/reporter.ts:509-561). With an active Allure test plan, the retried attempt may miss required labels or be reported even when the scenario should be filtered. Consider refactoring the common scenario-test initialization into a helper that both onSuiteStart and onSuiteRetry call so behavior stays consistent (including test plan labeling/skipping).

Copilot uses AI. Check for mistakes.
Comment on lines +922 to +923
const firstAttemptSuite = cucumberHelper.scenarioEnd({ tests: [cucumberHelper.testFail()], hooks: [] })
reporter.onSuiteRetry(firstAttemptSuite as any)
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test calls onSuiteRetry with cucumberHelper.scenarioEnd(...), which includes tests/hooks data; however, in the actual WDIO pipeline the suite:retry listener calls suiteStat.retry() before invoking onSuiteRetry, which clears suiteStat.tests/suiteStat.hooks (packages/wdio-reporter/src/index.ts:102-106, packages/wdio-reporter/src/stats/suite.ts:64-69). As written, the test doesn't match the real event object shape and can mask issues in the retry-status/error deduction logic. Consider adjusting the test to pass a SuiteStats instance (or manually clear tests/hooks before calling onSuiteRetry) to reflect production behavior.

Suggested change
const firstAttemptSuite = cucumberHelper.scenarioEnd({ tests: [cucumberHelper.testFail()], hooks: [] })
reporter.onSuiteRetry(firstAttemptSuite as any)
// In the WDIO pipeline, suiteStat.retry() clears tests/hooks before onSuiteRetry runs.
const firstAttemptSuite: any = cucumberHelper.scenarioEnd({ tests: [cucumberHelper.testFail()], hooks: [] })
firstAttemptSuite.tests = []
firstAttemptSuite.hooks = []
reporter.onSuiteRetry(firstAttemptSuite)

Copilot uses AI. Check for mistakes.
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.

[🐛 Bug]: Retried tests do not appear as retries in Allure report

2 participants