behat-screenshot icon indicating copy to clipboard operation
behat-screenshot copied to clipboard

#61: Event dispatcher is breaking Pretty formatter

Open marcelovani opened this issue 2 years ago • 6 comments

##What this PR does

  • Fixed the issue where Pretty formatter was not working with Cucumber json formatter
  • Removed old Event
  • Implementation using static cache for the image urls.
  • Added tag to the image uploader service, to be used by Cucumber reports to get the service using tag id.
  • Updated Cucumber PR https://github.com/cawolf/behat-cucumber-formatter/pull/12/files

marcelovani avatar Jan 17 '23 15:01 marcelovani

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?

marcelovani avatar Jan 17 '23 19:01 marcelovani

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).

elvetemedve avatar Jan 17 '23 22:01 elvetemedve

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.

marcelovani avatar Jan 18 '23 09:01 marcelovani

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.

elvetemedve avatar Jan 18 '23 12:01 elvetemedve

Your are right, I just copy and pasted without reading the event name. I came up with a new solution, will post here soon.

marcelovani avatar Jan 19 '23 00:01 marcelovani

Description updated with new approach, please review. The nice thing is that it makes Cucumber extension configurable and no longer needs a hard dependency.

marcelovani avatar Jan 19 '23 00:01 marcelovani