Karate: [Feature Request]: Ability to change the displayName of a Feature in the report

Created on 14 Jun 2020  路  9Comments  路  Source: intuit/karate

At the moment, the name of a feature when displayed in a report is set to it's relative path, with prefix removed, as per the FeatureResult constructor:

public FeatureResult(Results results, Feature feature) { this.results = results; this.feature = feature; **displayName = FileUtils.removePrefix(feature.getRelativePath());** }

I just wondered if we could have the ability to edit displayName? (Possibly in a similar fashion to the 'setName()' method for Feature?)

I realize this may not be possible and that displayName may be private for a reason.

I also realize this may not matter to others. In my case, I am writing a framework on top of this (excellent) framework and every little helps in my effort of convincing people to use Karate instead of RESTAssured + 3rd party report plugin :)

enhancement fixed

All 9 comments

@karatekid5088 I was about to close this - but then figured that having the ability to customize the "name as it appears in the HTML report" may be a good thing to have, if that is what you are asking. and that it should be possible from within a running test. is that right ?

or you seem to be trying to do this from Java code. can you explain what you are trying to do soa that it can be part of the base framework if needed ?

Thanks for hearing me out Peter. Initially (preferably) I had thought this could be done from Java code, but I'm open to ideas. Here is some background to help paint the picture, you can skip to the last part for the specific feature request.

Context
On the 'Features' page of the cucumber-html-reports plugin (and indeed, the Trivago cluecumber plugin, or whatever plugin is used) - the 'Feature' column is like so:

image

It is this value that I'm keen on being able to edit.

Currently in Java, I build our report using the method recommended in the docs. I believe (unless mistaken) that the feature titles in the screenshots above are set in the constructor of com.intuit.karate.core.FeatureResult, specifically by this line 118: displayName = FileUtils.removePrefix(feature.getRelativePath());.

  • This is then saved to the XML/JSON output in /surefire-reports dir (e.g. class com.intuit.karate.core.Engine, method saveResultJson).
  • Appearance in JSON: "name": "demo\/call-array\/call-json-array.feature"
  • Which is then in turn picked up by net.masterthought.cucumber.ReportBuilder (or whatever report plugin is being used). Somewhere in this phase, a call to getDisplayName() is made. In its current form, this will always be the feature file's relative path.

Possible Solution

Before the call to the ReportBuilder class (ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);) - I could parse the Results object returned by .parallel(x,y,z) and edit the FeatureResult.displayName here. Either that, or I could edit it during the afterScenario method of my Java hook which implements ExecutionHook.

Currently this cannot be done because displayName is private and does not have setter (in the same way we have setName() for a Feature object).

The Feature Request
Ultimately - the ask here is to permit the editing of displayName in the Java code, via a setDisplayName() setter or whichever way is practical/possible.

This way, the displayName could remain the relative path by default, like in screenshot above. But it would also give people the option to change it to something else, if they'd like to.

I'd be open to this happening in the Karate DSL code / karate-config.js too, but I think having this in Java would present more flexibility (imo).

@karatekid5088 that's an easy change, see commit - does it work for you ?

@ptrthomas Perfect - just wanted to make sure if would not cause any unwanted behavior elsewhere. Thank you :)

@ptrthomas Hello, just wondered if this will be available in 0.9.6.RC4 (if there is one), or 0.9.6? Purely just to fill out repository request form.

@karatekid5088 yes I plan an RC4 next week

@ptrthomas hello peter. is there still a plan to do an RC4? Kind regards.

@karatekid5088 yes but it is indeed delayed. will try for next week. you can build from source any time as you know.

I learnt about this trick recently, maybe it helps for you in the meantime ? https://twitter.com/maxandersen/status/1277116280542281729

0.9.6 released

Was this page helpful?
0 / 5 - 0 ratings