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

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
What I want to achieve:
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?

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?

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

Related

Is there a class/variable of karate available to get the details of failed scenarios like failed Scenario name, count etc when run using TestRunner

I want to get the details of the failed testcase after running it using TestRunner class. I was able to get few details like error messages, failed count of scenarios and feature files using the Result class of karate.
Results results = Runner.path("classpath:errorData/pass.feature").parallel(5);
String errmsgs = results.getErrorMessages();
List<String> err = results.getErrors();
int failcount = results.getFailCount();
Now I wanted to know if there is a way to get the details like testcase status, failed scenario, failed step. Any input will be appreciated. Thanks in advance
If you can't find what you need in the Result class, please assume the answer is no. Since Karate is open source, you are welcome to figure this out yourself or contribute code for anything missing.

Serenity BDD report generation

We are trying to generate reports for our tests using serenity BDD. But we couldn't find anything to help with report generation.If anyone is familiar with this,Please suggest any simple way to achieve this.
To generate a report you need to use apply plugin: 'net.serenity-bdd.aggregator' plugin in your build.gradle file. Also while executing your project use gradlew clean test aggregate command from your command line.
After execution you will find index.html report under \target\site\serenity
You can use the Groovy MarkUpBuilder and create customized reports for your use case. Basically, you'll need to create a markup builder instance in Groovy as below :
def xmlWriter = new FileWriter(file("${project.buildDir}/index.html"))
def xmlMarkup = new MarkupBuilder(xmlWriter)
Create custom tags using below sytax :
xmlMarkup.myCustomTag("Lorem Ipsum")
which will produce :
<myCustomTag>Lorem Ipsum</myCustomTag>
So, for a syntax like xmlMarkup.h1("Lorem Ipsum") you'll get the output as <h1>Lorem Ipsum</h1>
Then you can just create a gradle task which parses all the test outputs (xml or json) into HTML.
I had written an article about that in the past which you can find here

NUnit - Running specific test case using testcase attribute through command line

I want to run the below test case through nunit console using command line.`
class ListCities : Test.HelperClasses.Testbase
{
[TestCase(Category="smoke",TestName = "TC1", Description = "dessciption")]
public void SearchCity()
{
}
}`
I tried the command --test=Test.HelperClasses.Testbase.ListCities.TC1.
But i want to execute the test using only testname(TC1) attribute and not along with the namespace(Test.HelperClasses.Testbase) and class name(ListCities).
Below is the python code to execute the test case using nunit console
os.system("Call "+NunitPath+" "+dllPath+" --
test=Test.HelperClasses.Testbase.ListCities.TC1 --result="+resultPath)
Thanks in advance
The TestName property of TestCaseAttribute only sets the name of the test. The --test option of the console runner uses the full name of the test. The alternative you tried is the right way to specify this test case - that's how NUnit works.
If you want to have a more succinct syntax, read the documentation for the --where option. It would allow you to do something like --where test=~TC1.

Integrating RFT Test framework to work with RQM

I designed a framework in RFT where the test cases are written in spreadsheet specifying the data source, object and keyword and a driver script which processes through all this data and routes it to the appropriate method for each test step all in a spreadsheet. Now I want to integrate this with RQM so that each of my test cases in the spreadsheet is shown as passed/failed in RQM. Any ideas?
You could implement now an algorithm to read those testcases in the spreadsheet and pass them to RQM as attachments with logTestResult.
For example:
logTestResult( <your attachment> , true );
And if you are already connected to RQM the adapter will attach files that you indicate automatically to RQM. So, at the end you will see step by step the results and if the script ends correctly RQM will show you the script as "passed".
Thanks for the answer Juan. I solved this by passing the testcase name from Script Argument part of RQM and fetching the arguments in my starter script as shown below:-
public void testMain(Object[] args) throws Exception
{
String n=args[0].toString();
logInfo("Parameter from RQM"+n);
ModuleDriver d=new ModuleDriver();
d.execute_main(n);
}
Since I have verification points setup for each of the steps in my test cases the results get reported based on each of those verification points in RQM which is what i needed.

Getting failure detail on failed scala/maven/specs tests

I am playing a bit with scala, using maven and scala plugin.
I can't find a way to have
mvn test
report failure details - in particular, whenever some function returns wrong reply, I am getting information about the failure, but I have no way to see WHICH wrong reply was reported.
For example, with test like:
object MyTestSpec extends Specification {
"my_function" should {
"return proper value for 3" {
val cnt = MyCode.my_function(3)
cnt must be_==(3)
}
}
}
in case my function returns something different than 3, I get only
Failed tests:
my_function should return proper value for 3
but there is no information what value was actually returned.
Is it possible to get this info somehow (apart from injecting manual println's)?
The Maven JUnit plugin only shows the failed tests in the console and not error messages. If you want to read the failure message you need to open the corresponding target/site/surefire-reports/MyTestSpecs.txt file.
You can also swap Maven for sbt-0.6.9 (Simple Build Tool) which can run specs specifications.
Eric.
cnt aka "my_function return value" must be_==(3)