Skip to content

Commit

Permalink
feat: display command name for webdriver calls in allure reporter for…
Browse files Browse the repository at this point in the history
… v8 (#12986)

* feat: display command name for webdriver calls in allure reporter

* Add unit tests

* Ignore endpoint from stepname when command name is present
  • Loading branch information
sudharsan-selvaraj committed Jun 10, 2024
1 parent 5f5ff25 commit 48b7321
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/wdio-allure-reporter/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,12 @@ export default class AllureReporter extends WDIOReporter {
if (disableWebdriverStepsReporting || this._isMultiremote) {
return
}
const { method, endpoint } = command

const stepName = command.method ? `${command.method} ${command.endpoint}` : command.command as string
const stepName = command.command ? command.command : `${method} ${endpoint}`
const payload = command.body || command.params

this._startStep(stepName)
this._startStep(stepName as string)

if (!isEmpty(payload)) {
this.attachJSON('Request', payload)
Expand Down
65 changes: 65 additions & 0 deletions packages/wdio-allure-reporter/tests/allureFeatures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,68 @@ describe('nested suite naming', () => {
expect(childSuite).not.toBeUndefined()
})
})

describe('test step naming', () => {
const outputDir = temporaryDirectory()
let reporter: any

beforeEach(() => {
clean(outputDir)
reporter = new AllureReporter({ outputDir, disableMochaHooks: false })
})

it('should display command name when both command name and enpoint are available ', () => {
const command = {
command: 'SomeCommandStep',
method: 'POST',
endpoint: '/session/:sessionId/element',
}
reporter.onRunnerStart(runnerStart())
reporter.onSuiteStart(testStart())
reporter.onTestStart(testStart())
reporter.onBeforeCommand(command)
reporter.onAfterCommand(command)
reporter.onTestPass()
reporter.onSuiteEnd(suiteEnd())
reporter.onRunnerEnd(runnerEnd())

const { results } = getResults(outputDir)
const testResult = results.find(
(result) => result.name === 'should can do something'
)

expect(results).toHaveLength(1)
expect(testResult).not.toBeUndefined()
expect(testResult.steps).toHaveLength(1)
expect(testResult.steps[0].name).toEqual(
'SomeCommandStep'
)
})

it('should display the endpoint and method in the absence of command name', () => {
const command = {
method: 'POST',
endpoint: '/session/:sessionId/element',
}
reporter.onRunnerStart(runnerStart())
reporter.onSuiteStart(testStart())
reporter.onTestStart(testStart())
reporter.onBeforeCommand(command)
reporter.onAfterCommand(command)
reporter.onTestPass()
reporter.onSuiteEnd(suiteEnd())
reporter.onRunnerEnd(runnerEnd())

const { results } = getResults(outputDir)
const testResult = results.find(
(result) => result.name === 'should can do something'
)

expect(results).toHaveLength(1)
expect(testResult).not.toBeUndefined()
expect(testResult.steps).toHaveLength(1)
expect(testResult.steps[0].name).toEqual(
'POST /session/:sessionId/element'
)
})
})
4 changes: 2 additions & 2 deletions packages/webdriver/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default function (

const request = await RequestFactory.getInstance(method, endpoint, body, isHubCommand)
request.on('performance', (...args) => this.emit('request.performance', ...args))
this.emit('command', { method, endpoint, body })
this.emit('command', { command, method, endpoint, body })
log.info('COMMAND', commandCallStructure(command, args))
/**
* use then here so we can better unit test what happens before and after the request
Expand All @@ -136,7 +136,7 @@ export default function (
log.info('RESULT', resultLog)
}

this.emit('result', { method, endpoint, body, result })
this.emit('result', { command, method, endpoint, body, result })

if (command === 'deleteSession') {
const shutdownDriver = body.deleteSessionOpts?.shutdownDriver !== false
Expand Down

0 comments on commit 48b7321

Please sign in to comment.