Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pr-279.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wdio/browserstack-service": minor
---

- `browser.setCustomTags()` now works with WebdriverIO + CucumberJS: custom metadata set in steps or Cucumber `Before`/`After` hooks is reported on the scenario in Test Reporting & Analytics.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TestFrameworkState } from '../states/testFrameworkState.js'
import { TestFrameworkConstants } from '../frameworks/constants/testFrameworkConstants.js'
import { CLIUtils } from '../cliUtils.js'
import WdioMochaTestFramework from '../frameworks/wdioMochaTestFramework.js'
import WdioCucumberTestFramework from '../frameworks/wdioCucumberTestFramework.js'
import { BrowserstackCLI } from '../index.js'
import { mergeIntoTags, parseCommaSeparatedValues, getCurrentMochaHookWindow } from '../../customTags.js'
import type { CustomMetadata } from '../../customTags.js'
Expand Down Expand Up @@ -55,8 +56,9 @@ export default class CustomTagsModule extends BaseModule {
return CustomTagsModule.MODULE_NAME
}

private isMochaFramework(): boolean {
return BrowserstackCLI.getInstance().getTestFramework() instanceof WdioMochaTestFramework
private isSupportedFramework(): boolean {
const framework = BrowserstackCLI.getInstance().getTestFramework()
return framework instanceof WdioMochaTestFramework || framework instanceof WdioCucumberTestFramework
}

async onBeforeExecute() {
Expand All @@ -75,14 +77,11 @@ export default class CustomTagsModule extends BaseModule {

(browser as WebdriverIO.Browser).setCustomTags = async (key: string, value: string): Promise<void> => {
try {
// Mocha-only, matching the legacy handler (custom-tags-handler, which warns
// and no-ops for any framework other than mocha). The method is still
// registered so the call resolves and the warning reaches the user, exactly
// as on the legacy flow. Without this gate the CLI path silently STARTS
// supporting custom tags for other frameworks — a widening, but an
// unrequested behaviour change all the same.
if (!this.isMochaFramework()) {
this.logger.warn('setCustomTags is only supported for the mocha framework; ignoring call')
// Registered for every framework so the call always resolves; only the
// CLI frameworks that mint a per-test instance (a Mocha test, a Cucumber
// scenario) can carry the tags.
if (!this.isSupportedFramework()) {
this.logger.warn('setCustomTags is only supported for the mocha and cucumber frameworks; ignoring call')
return
}
if (!key || !value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import { BrowserstackCLI } from '../../../src/cli/index.js'
import { BStackLogger } from '../../../src/cli/cliLogger.js'

/**
* 8-D. `setCustomTags` warns and no-ops for every framework except mocha, which
* is what the legacy custom-tags-handler does. Discriminating: the SAME call merges tags under
* mocha and merges nothing under cucumber.
* `setCustomTags` merges for the CLI-supported frameworks (mocha, cucumber) and warns and
* no-ops when no CLI test framework is registered.
*/
describe('CustomTagsModule — framework gate', () => {
let module: CustomTagsModule
Expand Down Expand Up @@ -82,16 +81,16 @@ describe('CustomTagsModule — framework gate', () => {
expect(instance.updateMultipleEntries).toHaveBeenCalled()
})

it('warns and no-ops for cucumber — the opposite answer on the same call', async () => {
it('merges tags into the current scenario for cucumber', async () => {
useFramework(Object.create(WdioCucumberTestFramework.prototype))
const setCustomTags = await register()

await setCustomTags('TC', 'TC-1,TC-2')

expect(instance.updateMultipleEntries).not.toHaveBeenCalled()
expect(BStackLogger.warn).toHaveBeenCalledWith(
'setCustomTags is only supported for the mocha framework; ignoring call'
)
expect(instance.updateMultipleEntries).toHaveBeenCalledWith({
custom_metadata: { TC: { field_type: 'multi_dropdown', values: ['TC-1', 'TC-2'] } }
})
expect(BStackLogger.warn).not.toHaveBeenCalled()
})

it('warns and no-ops when no CLI test framework is registered', async () => {
Expand All @@ -102,7 +101,7 @@ describe('CustomTagsModule — framework gate', () => {

expect(instance.updateMultipleEntries).not.toHaveBeenCalled()
expect(BStackLogger.warn).toHaveBeenCalledWith(
'setCustomTags is only supported for the mocha framework; ignoring call'
'setCustomTags is only supported for the mocha and cucumber frameworks; ignoring call'
)
})
})
Loading