Before and After Step hooks should not generate step entries
osmolyar opened this issue · 8 comments
Environment (please complete the following information):
Node.js version: [12.9.0]
- NPM version: [ 6.14.4]
- webdriver.io version: [7]
- @wdio/cucumber-framework version: [. 7.0.7]
- wdio-cucumberjs-json-reporter version: [4.1.1]
Config of webdriver.io and the reporter
[
'cucumberjs-json',
{
jsonFolder: 'testResults',
language: 'en'
},
],
Describe the bug
The onHookStart and onHookEnd handlers generate entries in the steps array for Keyword "Before" and Keyword "After" ( beforeStep and afterStep hooks are defined in the test suite, but the onHookStart and onHookEnd handlers presumably get triggered for any hooks (?) ) . These step entries have a blank "name", which is not supported by QMetry's test upload API and causes the entire upload to fail to upload test results.
Not quite sure what the requirements is for outputting these as "steps" since the hooks are not steps in the scenario. The following commenting produced the desired behavior. Suggest not handling the hooks in the reporter.
onHookStart(payload) {
const currentSteps = this.getCurrentScenario().steps;
payload.state = constants_1.PASSED;
payload.keyword = this.utilsObject.containsSteps(currentSteps, this.options.language) ? constants_1.AFTER : constants_1.BEFORE;
// this.addStepData(payload);
}
onHookEnd(payload) {
payload.state = payload.error ? payload.state : constants_1.PASSED;
// return this.updateStepStatus(payload);
}
To Reproduce
Steps to reproduce the behavior:
Generic feature file, with beforeStep and afterStep hooks defined for the suite
Expected behavior
A clear and concise description of what you expected to happen.
Hooks should not generate entries in the steps array since they are not scenario steps.
Snapshots
If applicable, add snapshots to help explain your problem.
Additional context
Add any other context about the problem here.
Thanks @osmolyar
I need to dive into this to, not sure what is allowed according to the official docs. The problem is that I don't have a lot of time currently to work on this so any help would be appreciated
I'm still not sure how this should be handled. Hooks can also have an impact on a test, they can have data attached to it like a screenshot. For now I'm keeping them in unless someone else has other information. (I still haven't found an instruction how a valid JSON should look like for Cucumber)
QMetry has modified their result uploader API so that
"• When the "name" attribute for a test step in the result file is empty, the "keyword" attribute gets imported as the step description."
so the blank "name" field on these steps is no longer an issue. (Closing issue.)
It turns out that even though QMetry modified their API as above, the test case steps get uploaded like this (because they now use the keyword value for the step name when step name is blank) :
It seems undesirable to have hook names with no content handled as test steps from this perspective. We can locally modify the reporter package but I've not seen any cucumber reporters doing this before. They may also modify their uploader to skip the hooks entirely.
Hi All,
Just to mention one thing on this. It would be nice to have that config level feature on this which means "disableHooks" property. hence it wont generate the hooks information in JSON file.
what do you guys think?
That's a good one, do you want to take a stab at it in a PR?
Thanks for the PR @bhaslamb
I've released version https://github.com/webdriverio-community/wdio-cucumberjs-json-reporter/releases/tag/v4.3.0, please try that one out by updating your dependencies and add disablehooks:true
to the service properties