Is it possible to access a specific TestStep logs through TestStepRun variable ?
I’m building a ResultListener and I’d like to get access to logs per TestStep instead of the big logStream that I get OnTestPlanRunCompleted.
Hi @matcap, it’s not possible to get it through the TestStepRun variablebut it is possible to attach a custom log listener by calling OpenTap.Log.AddListener. You could for example do that in ResultListener.Open and then remove it at ResultListener.Close.
Since all log processing is handled in a separate you need to flush the log to make sure that all the events are handled before actually using it for anything.
Also, since the logs are handled asynchronously, the log might not be finished processing when you get to TestStepRunCompleted for the specific step. You can flush at that time, but it might slow down your test plan somewhat if you need to synchronize these threads. Anyway, you will get a warning in the log if that happens.strong text
Ok thank you, I’ll try implementing that. It might not be sufficient as some steps publish logs asynchronously after step completion.
On a similar note do you know if there is an easy way to link Results to the TestStep they come from ? After debugging, it seems that OnResultPublished’s stepRunId is not the same thing as stepRun.TestStepId so results can’t be matched to Steps.
Getting the logs
OK, so in case they are your test steps, if they need to do stuff asynchronously, you could consider using Results.Defer to do that. That will let OpenTAP continue with other steps even though parts of the old test step continues in the background. That way you can still keep track of the messages, because you will only get the TestStepRunCompleted after the deferred work is done.
Connecting TestSteps and Results
To figure out which TestStep a given result comes from, you need to use the TestStepRunId to lookup (you have to keep track of it yourself) which TestStepRun a given result belongs to. Using the TestStepRun, you can find the test step ID.
Note, there is no easy way of getting TestStep instance from the ID and it’s not recommended to try to do that. For sharing data between steps we recommend finding another way.
Getting the logs
I’m indeed using Results.Defer but didn’t know TestStepRunCompleted would happen after results processing.
Connecting TestSteps and Results
I was using stepRun.TestStepId instead of stepRun.Id, it works now, thanks !