kmnaid / wdio-slack-reporter

MIT License
2 stars 3 forks source link

Make reporter compatible with WDIO v5 #3

Open tzero86 opened 5 years ago

tzero86 commented 5 years ago

Hello,

WebdriverIO released version 5 around Christmas, see here (https://webdriver.io/blog/2018/12/19/webdriverio-v5-released.html).

To make this reporter usable with the new version, some adjustments are required. You can find a general overview of those here (https://webdriver.io/docs/customreporter.html).

Most important changes to point out provided on this link: fijijavis/wdio-mochawesome-reporter#36

It would be great if you can update the reporter to work with this new WDIO version.

Thank you!

kmnaid commented 5 years ago

@tzero86 Thanks for the details. I am working on it.

kmnaid commented 5 years ago

@christian-bromann Hello, V4 reporters had access to an 'end' event which is not available to the reporters in v5. How do you suggest handling it in this custom reporter where the slack notifications need to be sent just once after the all suites are complete? Thanks.

kevinmcdonnell commented 5 years ago

looks like extending reporter gives access to a number of events https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-reporter#webdriverio-reporter

I've also seen references to the following events in the code

test:end
suite:end
runner:end
kmnaid commented 5 years ago

@kevinmcdonnell : With the events available currently through @wdio/reporter results can be aggregated maximum up to the suite/spec level. So each spec files results would be sent as a separate slack message/notification. We would want the results of all spec files including the summary to be sent as one single notification for which given the available events in @wdio/reporter it's not possible.

kevinmcdonnell commented 5 years ago

ah I see. The onComplete hook in wdio.conf.js has summary test data. I was able to write a script which uses that to post to slack. Gist attached if it helps anyone

https://gist.github.com/kevinmcdonnell/e3ecb713165a11b89f385dfadeba3525

dragancla commented 5 years ago

@kevinmcdonnell hi, thanks for that, I managed to adapt it for our tests :)

Is there any way to get the paths of the files that failed, the number of tests failed (instead of number of specs) and the duration of the suite?

kevinmcdonnell commented 5 years ago

We just linked to our allure report.

You could create your own duration? Just start a timer onPrepare and end onComplete?

There's an afterTest hook. In that you could check if the test failed. You could push those to an array and the read them in the slack reporter and link to them.

Let me know if you need an example

dragancla commented 5 years ago

No, it's fine. I was actually hoping that there's some way to access the old v4 stats object in the onComplete hook, it would have been a lot easier

christian-bromann commented 5 years ago

@dragancla unfortunately reporter moved into the worker process in v5 and therefor don't have access to any onComplete hook whatsoever.

dragancla commented 5 years ago

@christian-bromann yeah, that kept popping up all day while I was looking for a solution for this. we've started porting to v5 and we would love the same functionality of one-slack-notification-per-suite, I guess it's not going to be supported and we have to append results to a json ourselves from the afterTest hook and read the data from there?

kmnaid commented 5 years ago

@dragancla : Yes, that's right. You could use wdio-json-reporter to get the merged results.

dragancla commented 5 years ago

@kmnaid I was just looking into @kevinmcdonnell 's project, I'll try it tomorrow when I get to the office, thanks!

dragancla commented 5 years ago

It works, thanks :) Also, for the sake of convenience, I modified the mergeResults script to run programatically in the onComplete hook, paired with a nice clean-up function for old json files in the onPrepare hook 👍