1
votes

I am running Cucumber features using AbstractTestNGCucumberTests.

Each feature file has one corresponding Runner class which extends the AbstractTestNGCucumberTests class.

public class LoginRunner extends AbstractTestNGCucumberTests {
}

public class CreateAccountRunner extends AbstractTestNGCucumberTests {
}

I am also using a Cucumber reporting listener which is an implementation of the ISuiteListener. On finish, the Cucumber ReportBuilder will generate the reports.

public class CucumberReporting implements ISuiteListener{//}

My TestNG.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
    <listeners>
        <listener
                class-name="listeners.reportlistener.CucumberReport" />
    </listeners>
    <test name="Test - 1">
        <classes>
            <class name="testrunner.LoginRunner" />
            <class name="testrunner.CreateAccountRunner" />
        </classes>
    </test>
</suite>

As you can see there are two runner classes. When I run testng.xml it executes one runner class and then moves to the next.

In this situation, only the last run feature file is generating the Cucumber report. In other words the reports are getting overwritten. And every run of the xml ends up with one single HTML report.

How can I generate one single report which has results from both the runner classes?

4

4 Answers

1
votes

I think, y need to merge xml report files. Save each file with unique name, and then merge it. This might help:

Click

1
votes

Best option is to create a new Runner class which will print all the data. Example:

@CucumberOptions(
        format = {...},
        features = {"src/test/resource"} //All the feature files must be present here.
        )
public class CucumberTagRunnerTest {

}

Moreover, for selective report, you can use @tag in the feature files and print results specific to the test cases which are specific to @tag only. @tag - can be used specific to complete feature file or to some test-cases as well.

@CucumberOptions(
        format = {...},
        features = {"src/test/resource"},
        tags = {"@tag"} //Like this.
        )
public class CucumberTagRunnerTest {

}

In all feature files:

@tag
Feature: Proof of Concept
  I want to use this template for my feature file
  ...

I hope this helps.

0
votes

There are 2 ways you can approach it.

First way, run the feature files using a testng suite xml configuration and then use the testng report. You can customize this report to meet your needs. Use IReporter interface interface of testNG.

Second way, when u define format in options give different folders for different features. Then write a utility to merge all reports to one file.

0
votes

There is a one way to get one single report. Put all your runner files in a package and use that package name in the testNG.xml file to execute the test. I did the same thing as below.

You Just have to give your package name like: package name="testRunner" in textNG.xml and run your suite by right clicking on testNG.xml file and select runas TestNG test from Eclipse.

Poject structure that showcase testrunner package

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="BDD Test Suite" verbose="1" parallel="classes" thread-count="2" configfailurepolicy="continue">
        <listeners>       
            <listener class-name="managers.LocalWebDriverListener" />
        </listeners>

         <test name="Chrome Test">
            <parameter name="browserName" value="chrome"/>
            <packages>
                <package name="testRunner"/>
             </packages>
         </test>

       <test name="Firefox Test">
         <parameter name="browserName" value="firefox"/>
         <packages>
            <package name="testRunner"/>
         </packages>     
        </test>

    </suite>