Open davidrova opened 6 years ago
Hi David,
Thanks for your feedback. I didn't realise anyone was actually using this reporter, so its nice to see its not just me 😄
A couple of quick questions:
framework
are you using with your webdriver.io tests? (cucumber, mocha, jasmine etc)
Would adding a takeScreenshot()
call after each step achieve the same result of taking a screenshot on failure? e.g.
exports.config = {
capabilities: [],
...
afterStep: function(stepResult) {
if (stepResult.status === 'failed') {
let filename = 'stepFailErrorScreenshot'
process.send({
event: 'screenshot:fullpage',
filename: `${filename}.png`,
})
let browserLog = browser.log('browser')
process.send({
event: 'runner:logit',
output: browserLog,
})
}
}
}
I would like to take a screenshot in each step, because when there's a controlled failure (expect....), by default you cannot take an screenshot.
Methods managing events 'runner:screenshot' and 'screenshot:fullpage' don't control when last entry is the feature or the scenario.
It seems webdriverio throws the event on each sentence (feature, scenario, step). If you are not in a scenario, steps node will be empty.
This is my workaround (I don't have rights to commit in the repository):
this.on('runner:screenshot', function (runner) { const cid = runner.cid const stats = this.baseReporter.stats const results = stats.runners[cid] const specHash = stats.getSpecHash(runner) const spec = results.specs[specHash] const lastKey = Object.keys(spec.suites)[Object.keys(spec.suites).length-1] const currentTestKey = Object.keys(spec.suites[lastKey].tests)[Object.keys(spec.suites[lastKey].tests).length-1] if (spec.suites[lastKey].tests[currentTestKey]) { spec.suites[lastKey].tests[currentTestKey].screenshots.push(runner.filename) } }) this.on('screenshot:fullpage', function (data) { const cid = data.cid const stats = this.baseReporter.stats const results = stats.runners[cid] const specHash = Object.keys(results.specs)[Object.keys(results.specs).length-1] const spec = results.specs[specHash] const lastKey = Object.keys(spec.suites)[Object.keys(spec.suites).length-1] const currentTestKey = Object.keys(spec.suites[lastKey].tests)[Object.keys(spec.suites[lastKey].tests).length-1] if (spec.suites[lastKey].tests[currentTestKey]) { spec.suites[lastKey].tests[currentTestKey].screenshots.push(data.filename) } })