How to write a custom Failure message for the Failed Step in Cucumber-java in extentReports
Asked Answered
O

2

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?

Oilcloth answered 2/12, 2016 at 10:32 Comment(3)
were you able to figure a way to do this?Mossback
Nope! not yet..Oilcloth
@SakshiSingla Incase your Question is still unanswered can consider updating the Cucumber jar versions cucumber-core,cucumber-java,cucumber-junit and ExtentReports version? ThanksBookstand
V
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?

Voiture answered 11/10, 2017 at 14:41 Comment(0)
I
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

Inapprehensive answered 1/8, 2019 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.