[英]Any way to create one single Cucumber report for multiple feature files run by as many Runner classes?
I am running Cucumber features using AbstractTestNGCucumberTests. 我正在使用AbstractTestNGCucumberTests运行Cucumber功能。
Each feature file has one corresponding Runner class which extends the AbstractTestNGCucumberTests class. 每个功能文件都有一个对应的Runner类,该类扩展了AbstractTestNGCucumberTests类。
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. 我还使用了Cucumber报告侦听器,该侦听器是ISuiteListener的实现。 On finish, the Cucumber ReportBuilder will generate the reports. 完成后,Cucumber ReportBuilder将生成报告。
public class CucumberReporting implements ISuiteListener{//}
My TestNG.xml looks like this: 我的TestNG.xml看起来像这样:
<?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. 当我运行testng.xml时,它将执行一个运行程序类,然后移至下一个。
In this situation, only the last run feature file is generating the Cucumber report. 在这种情况下,只有最后运行的功能文件才生成Cucumber报告。 In other words the reports are getting overwritten. 换句话说,报告将被覆盖。 And every run of the xml ends up with one single HTML report. 每次运行xml都只有一个HTML报告。
How can I generate one single report which has results from both the runner classes? 如何生成一个同时包含两个跑步者类成绩的报告?
Best option is to create a new Runner class which will print all the data. 最好的选择是创建一个新的Runner类,该类将打印所有数据。 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并打印特定于测试用例的结果,这些结果仅适用于@tag。 @tag - can be used specific to complete feature file or to some test-cases as well. @tag-可以用于完整的功能文件或某些测试用例。
@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. 我希望这有帮助。
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. 首先,使用testng套件xml配置运行功能文件,然后使用testng报告。 You can customize this report to meet your needs. 您可以自定义此报告以满足您的需求。 Use IReporter interface interface of testNG. 使用testNG的IReporter接口。
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. 然后编写一个实用程序,将所有报告合并到一个文件中。
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. 将所有运行程序文件放入包中,并在testNG.xml
文件中使用该包名称执行测试。 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. 您只需要在textNG.xml
提供软件包名称,例如:package name =“ testRunner”, textNG.xml
右键单击testNG.xml文件并从Eclipse中选择runas TestNG test textNG.xml
运行您的套件。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.