Open marcelovani opened 1 year ago
I debugged the listeners for service id event_dispatcher
:
array(3) {
[0]=>
string(29) "tester.scenario_tested.before"
[1]=>
string(28) "tester.example_tested.before"
[2]=>
string(31) "tester.exercise_completed.after"
}
I am stuck. If I change the id to bex.screenshot_extension.event_dispatcher
the Pretty formatter
and Progress formatter
will work, but the event being dispatched doesn't work, because there are no listeners.
@elvetemedve Do you have any suggestions to fix this?
Without looking into it deeper, I believe the problem is that you have two instances of the EventDispatcher
one is provided by Behat itself and the 2nd is what you defined in the services.xml
file of the extension.
If you give it the same service ID, it will overwrite the other, loosing the default listeners of Behat.
So I would remove the 2nd instance from service.xml
and pass the original instance somehow to ScreenshotUploader
(though it might be tricky to do if it's registered as a private service).
I am really struggling to find a solution.
Ideally we should not have to dispatch an event, because Behat already dispatches tester.scenario_tested.before
.
If we could find a way to have a soft dependency on behat-screenshot, at this point https://github.com/cawolf/behat-cucumber-formatter/pull/12/files#diff-b0c7aa6314a2629ca93e9c54ee90e3e11e3a637c35c8208f45914957e3d8ccabR260 we could try to get the behat-screenshot service and check if there is any screenshot, then we could remove a lot of code.
How would tester.scenario_tested.before
be useful here? Screenshot is uploaded later at ScenarioTested::AFTER
.
Alternatively you could try to pass the screenshot file information via one of the Behat events. Though I don't see any of these classes allowing extra info added. So it needs more investigation.
Your are right, I just copy and pasted without reading the event name. I came up with a new solution, will post here soon.
Description updated with new approach, please review. The nice thing is that it makes Cucumber extension configurable and no longer needs a hard dependency.
What this PR does