aruiz-caritsqa / wdio-html-format-reporter

A WebdriverIO plugin. Create a basic HTML formatted report
0 stars 4 forks source link

Error taking screenshots in each step #4

Open davidrova opened 6 years ago

davidrova commented 6 years ago

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) } })

aruiz-caritsqa commented 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: