Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Extend html-formatter and CustomRendering #76

Open
sashokbg opened this issue Oct 26, 2021 · 4 comments
Open

Documentation: Extend html-formatter and CustomRendering #76

sashokbg opened this issue Oct 26, 2021 · 4 comments

Comments

@sashokbg
Copy link

Documentation request:

Please add some examples on how to implement our own html-formatter based on the existing one.
It is difficult to understand how to properly use the "CustomRendering" to change the way different parts are rendered.

Describe the solution you'd like
A complete step-by-step guide that explains how to extend the html-formatter and how to override different elements' rendering.

Thank you for your help.

@aurelien-reeves
Copy link
Contributor

Did you had the opportunity to study the "react" component?

https://github.com/cucumber/common/tree/main/react/javascript

The HTML formatter is based on it. You may find more documentation, beginning with the README: https://github.com/cucumber/common/tree/main/react/javascript#cucumber-react

The HTML formatter javascript project is reponsible for building some html, css and javascript files using the "react" component. Then those html, css and javascript files are copied within other implementation - ruby and java - and used as templates.

In which language do you want to write your custom formatter?

@davidjgoss davidjgoss transferred this issue from cucumber/common Mar 3, 2022
@zbirizdo
Copy link

I would like to see some examples too please!

Should I write my own version of CucumberHtmlStream and somehow inject a CucumberReact component there so I can set the suggested customRendering attribute? I found this in cucumber/react-components:

<CucumberReact customRendering={{
  DocString: (props) => (
    <>
      <p>I am going to render this doc string in a textarea:</p>
      <textarea>{props.docString.content}</textarea>
    </>
  )
}}>
  <GherkinDocument />
</CucumberReact>

I am not a react developer and I don't really know what to do with this information (especially how is this going to get into my report).

Any help?

(by the way @aurelien-reeves your links are pointing to nowhere now)

@davidjgoss
Copy link
Contributor

davidjgoss commented Jun 10, 2023

Hey @sashokbg @zbirizdo, sorry for the late reply.

To give a little background, the motivation for making the components customisable was to layer on some extra functionality in the Reports service https://reports.cucumber.io/. We wanted to do this with a nice pattern that would potentially be useful to other consumers, but I’d say it’s somewhat incomplete - as you’ve noted, currently you’d need to essentially reimplement the html-formatter module to make use.

Would you mind elaborating a bit in the use cases you have and how you want to change/extend the output? Depending on what they are we may be able to support them in other ways eg configurability.

@zbirizdo
Copy link

zbirizdo commented Jul 1, 2023

Hi @davidjgoss, sorry for the late reply on my part too. I managed to solve my problem with a somewhat different approach.

About my problem... I am doing visual regression tests and I was able to insert multiple images into my report (so I can compare the reference image of the test with the current screenshot and the one containing the differences). It is really a pain in the a** to keep the reference images up to date manually so my idea was to further extend the report with an "Approve" button so I can just click through the changes.

In the end I realized that I can write a custom formatter based on the built in html formatter to generate the report as it is now, then tap into the finished method to insert some js into the report's html file. With that js I can manipulate the dom to make my changes without diving into react too deep or rewriting anything.

It is not a nice solution and I wouldn't recommend doing this with more complex functionality, but for just an extra button I'm fine with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants