10

I want to write custom failure message in my Cucumber ExtentReports.

Tool using :

Cucumber

Java

Selenium

JUnit

ExtentReports

What's happening now:

I have a cucumber scenario.

Given something
When I do something
Then this step fails

The failed step Fails with:

Assert.assertTrue("CUSTOM_FAIL_MSG", some_condition);

In the ExtentReport, I see the enter image description here

What I want to achieve:

enter image description here

What I have researched so far:

There is a scenario.write("") function but this creates a new info log into the report(But I am looking for CustomFailure message rather than a new log entry)

scenario.stepResults has the String which is displayed in the report. However, I could not find a way to set some value in the same.

Any ideas on this?

Craig
  • 7,471
  • 4
  • 29
  • 46
Sakshi Singla
  • 2,462
  • 1
  • 18
  • 34

2 Answers2

1

Have you tried using the create label markup?

Here is how to do it for the FAILED test:

test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Your MSG here!", ExtentColor.RED)); 

and the PASSED test:

test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));

You can easily manipulate the string part (var interpolation?) according to your need.

Does this help?

Xwris Stoixeia
  • 1,831
  • 21
  • 22
0

try to replace the JUnit assertion library with the testNG library...also using cucumber you can see the failed step...why do you want to change this "narrative" log?...or if you want a better report try to use a 3rd party library

realr
  • 3,652
  • 6
  • 23
  • 34
rusu dan
  • 21
  • 6