JoshKeegan / xRetry

Retry running tests via Xunit and Specflow
MIT License
53 stars 14 forks source link

Execute custom code when a retry happens #188

Open lobeu opened 1 year ago

lobeu commented 1 year ago

Hi,

Im using XRetry and I would like to be alerted when a retry happens.

In my case I'd like to send a slack message to a certain channel, but another use case could be to attach a custom logger. Almost all the projects I worked on test automation had a custom logger.

So is there a way to execute some custom code when a retry happens?

Ive tried a lot to do this:

Is there a way to add something for this maybe?

JoshKeegan commented 1 year ago

Hi,

is there a way to execute some custom code when a retry happens?

Not built-in. You'd need to either fork xRetry and add this, or enable diagnostic logs and then parsing them in a separate process to send alerts. I'd imagine parsing the logs in a separate process would be simpler than implementing it in a fork, and means you wouldn't have to worry about the additional code altering the way tests are run, e.g. by causing thread hopping.

Almost all the projects I worked on test automation had a custom logger

I think that would be beyond the scope of this project. Since xRetry is on top of xUnit, it just logs in the way xUnit makes available. If that were to ever be customisable it should be done via xUnit, or another plugin for it, rather than xRetry specifically offering a mechanism for a custom logger.

Trying to catch the DiagnosticMessage

I'm not sure what you mean by this as I don't know of anywhere it's exposed for a test to view.

lobeu commented 1 year ago

Okay, thanks for the info, I'll try to parse the diagnostic logs then. That's what I meant by "catching the DiagnosticMessage" by the way.

With the custom logger, I meant that it would be a good use case for being able to execute some code if a retry happens. I would then just log "Retrying" to a text file. That way we can see if it happens on a Jenkins run.