天天看點

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

1、extentreports 測試報告

pom檔案

<dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.40.2</version>
        </dependency>           
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>5.0.2.RELEASE</version>
    </dependency>           

cucumber入口類

  • CucumberOptions中加入插件的屬性
  • 在@BeforeClass注解方法中,可以使用setReportPath方法指定插件的報告生成位置
  • 在@AfterClass注解方法中,可以使用loadXMLConfig方法指定報告配置檔案的位置
package com.cucumber.demo;

import com.aventstack.extentreports.ResourceCDN;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.io.File;
//加入注釋語句位置,不能運作所有用例集合
//@RunWith(Cucumber.class)
@ContextConfiguration("classpath:cucumber.xml")
@CucumberOptions(
        plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/extent-report/report.html"},
        format = {"pretty", "html:target/cucumber", "json:target/cucumber.json"},
        features = {"src/test/resources/feature/"},
        glue = {"com.cucumber.demo","com.po.demo"},
        monochrome = true)
public class RunCukesTest extends AbstractTestNGCucumberTests {

    @BeforeClass
    public static void setup() {
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("target/extent-report/report.html");
        htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);

    }

    @AfterClass
    public static void tearDown() {
        Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));//1
        Reporter.setSystemInfo("user", System.getProperty("user.name"));
        Reporter.setSystemInfo("os", "Windows");
        Reporter.setTestRunnerOutput("Sample test runner output message");
    }

}           

extent-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<extentreports>
    <configuration>
        <theme>dark</theme>
        <encoding>UTF-8</encoding>
        <documentTitle>Cucumber Extent Reports</documentTitle>
        <reportName>Cucumber Extent Reports</reportName>
        <!--<reportHeadline> - v1.0.0</reportHeadline>-->
        <protocol>https</protocol>
        <dateFormat>yyyy-MM-dd</dateFormat>
        <timeFormat>HH:mm:ss</timeFormat>
        <scripts>
            <![CDATA[
                $(document).ready(function() {

                });
            ]]>
        </scripts>
        <!-- custom styles -->
        <styles>
            <![CDATA[

            ]]>
        </styles>
    </configuration>
</extentreports>           

2、jenkins持續內建

2.1、在Jenkins中安裝cucumber插件

需要安裝的插件如下:

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

2.2、釋出Cucumber測試結果報告

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

2.3、釋出HTML格式的報告

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

2.4、釋出Cucumber結果報告

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

2.5、點選應用儲存,并建構

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

2.6、建構完成後,效果如下

建構完之後,會多生成這兩個連結,點選Cucumber Reports後就可以看到好看的測試報告了,下面是部分截圖:

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建
行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

extentreport

行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建
行為驅動:Cucumber (二) - extentreports 測試報告+jenkins持續內建

注意:cucumber的run檔案不要使用标簽@runwith,批量執行多個feature檔案時

參考文章:

https://www.cnblogs.com/rechin/p/9411669.html

https://blog.csdn.net/qq_33320515/article/details/80648425

https://blog.csdn.net/qq_33320515/article/details/80648425

繼續閱讀