cawolf / behat-cucumber-formatter

Behat extension generating JSON reports
MIT License
3 stars 9 forks source link

Take screenshots and insert them in the json file #10

Open ramard opened 3 years ago

ramard commented 3 years ago

Is it possible to take screenshots with Mink and insert them in the json file like what we can have with Cucumber and the embeddings node ?

Thank you in advance.

cawolf commented 3 years ago

Hi, thank you for your question.

To be honest, I never thought about embedding screenshots in the JSON files. I actually take screenshots and publish them by another mechanism, but your idea sounds good to me.

Do you have any further documentation, how exactly this "embedding" should work?

ramard commented 3 years ago

Hi! Thank you for your answer.

I checked on how this was done on a Cucumber project and it seems that it is possible to add screenshots in the json file in this way: https://medium.com/@priyank.it/cucumber-report-taking-screenshot-embedding-inside-47d6d3c723bc

But I don't really know if it is possible to do the same with Behat.

cawolf commented 3 years ago

Yeah, I saw that article, too. I think it should be technically possible to add screenshots to the report. But how do you want to use these images?

Or, to rephrase: do you know the output format inside of the report? I can just assume it is maybe base64 encoded, carrying a mime type somehow, but that is just speculation.

Do you have an existing tool for showing the reports? Does it have some documentation about embedded screenshots?

ramard commented 3 years ago

I use your Behat extension to generate a JSON file for the Cluecumber tool (https://github.com/trivago/cluecumber-report-plugin).

So you can find on the example project, a JSON file with a screenshot in it : https://github.com/trivago/cluecumber-report-plugin/blob/main/example-project/json/scenario_with_attachments.json

I think it's a good output format.

cawolf commented 3 years ago

I see, and I can imaginge implementing and using it. The only problem is, that Behat itself does not provide an API like Cucumber does to embed these screenshots in the scenarios, so that output formatters may or may not use them.

So unless somebody adds this API to, let's say, the scenario class of Behat, this plugin has no access to that information. Or do you see another way?

ramard commented 3 years ago

Hi! Sorry for the answer time. Is it not possible to subscribe to events to know when the error happens and then add the screenshot with the JsonRenderer? If I take a screenshot extension for Behat, for example the bex/behat-screenshot extension, we can see an example of a screenshot listener (https://github.com/elvetemedve/behat-screenshot/blob/master/src/Bex/Behat/ScreenshotExtension/Listener/ScreenshotListener.php).

Do you think this could be possible?

marcelovani commented 1 year ago

I did a POC that seems to work for my needs. It requires changes on both packages, see

  1. https://github.com/elvetemedve/behat-screenshot/issues/58
  2. https://github.com/cawolf/behat-cucumber-formatter/pull/12

Please note that this PR will introduce a dependency on the Behat screenshot package.

marcelovani commented 1 year ago

PR updated https://github.com/cawolf/behat-cucumber-formatter/pull/12, please review the approach.

Screenshot 2023-01-19 at 00 30 53
cawolf commented 1 year ago

Thank you, I reviewed your PR and left some comments. In the meantime, I'm investigating on how to fix the test actions in general.

marcelovani commented 1 year ago

Comments addressed, please review again.