Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 539
Sakshi Singla Avatar asked Dec 02 '16 10:12

Sakshi Singla


1 Answers

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?

like image 151
Xwris Stoixeia Avatar answered Nov 01 '22 08:11

Xwris Stoixeia