sbabcoc / TestNG-Foundation

TestNG Foundation is a lightweight collection of TestNG listeners, interfaces, and static utility classes that supplement and augment the functionality provided by the TestNG API.
Apache License 2.0
13 stars 5 forks source link

ListenerChain does not support org.testng.IExecutionListener type of listeners #27

Closed psamovich closed 5 years ago

psamovich commented 5 years ago

It would be nice to add support for IExecutionListener type

sbabcoc commented 5 years ago

It's been a long time since I looked at this, but I think the reason I chose not to support IExecutionListener in ListenerChain is that the notifications published for this interface fire outside of the context I was able to capture. If you can figure out how to make this work, submit a pull request and I'll take a look.

Just for reference, why are you wanting to use ListenerChain to attach your execution listener instead of using the native TestNG attachment mechanism?

psamovich commented 5 years ago

We use a server solution (reportportal.io) for reporting, it's client use onExecutionStart and onExecutionFinish events to mark the beginning and ending of execution. In case the client handles other lower levels events like onTestStart without handling onExecutionStart the server returns error as the parent item (the whole test launch) hasn't started. And this happens if I load the report portal client listener via ListenerChain. Now about why do I need the specific order of listener execution. I have a bunch of test listeners which output some files which must be attached to the test in report portal e.g. screenshot, har, etc. These listeners must be executed before the report portal client handles onTestFinish event, because in case the test gets marked as finished the attachments won't be attached.

sbabcoc commented 5 years ago

Fixed by https://github.com/Nordstrom/TestNG-Foundation/pull/28
Note that this support must be activated via the ListenerChain service loader, as the onExecutionStart even fires before the @LinkedListeners annotations are processed.
This support is available in release 1.11.0 - Let me know how this works for you.
https://github.com/Nordstrom/TestNG-Foundation#specifying-listeners-to-attach-via-the-listenerchain-service-loader

psamovich commented 5 years ago

Works as expected when loading listeners via service loader. Thank you!