简体   繁体   English

是否可以为由多个Runner类运行的多个功能文件创建一个Cucumber报表?

[英]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? 如何生成一个同时包含两个跑步者类成绩的报告?

I think, y need to merge xml report files. 我认为,您需要合并xml报告文件。 Save each file with unique name, and then merge it. 用唯一的名称保存每个文件,然后将其合并。 This might help: 这可能会有所帮助:

Click 点击

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.

相关问题 执行多个黄瓜功能文件 - execute multiple cucumber feature files Cucumber Runner 不会使用空手道加载所有功能文件 - Cucumber Runner doesn't load all feature files using Karate Cucumber Runner 类抛出不安全的 http url TestNGException,但是我的 .feature 文件和 testng.xml 将运行该套件而不会出现问题 - Cucumber Runner class throws unsecured http url TestNGException, however my .feature files and testng.xml will run the suite without issues 如何并行运行 cucumber 功能文件 - How to Run cucumber Feature files in parallel 如何使用 Maven 通过命令提示符和 jenkins 运行单个黄瓜功能文件? - How to run single cucumber feature files through command prompt and through jenkins using Maven? 如何在同一浏览器窗口中一个接一个地运行一组Cucumber Feature文件? - How to run a group of Cucumber Feature files, one after another, in the same browser window? 有没有办法用我的Cucumber测试运行程序运行常规的jUnit测试? - Is there a way to run regular jUnit tests with my Cucumber test runner? 并行运行 cucumber 功能文件中的场景,一次一个功能文件 - Run scenarios in a cucumber feature file in parallel, one feature file at a time 无法运行 Cucumber 中的功能 - Cant run feature in Cucumber 没有任何功能文件的情况下如何运行黄瓜? - How can I run cucumber without any feature file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM