无法将屏幕截图附加到 Cucumber JVM 报告

Unable to attach screen shot to cucumber JVM report

我在我的项目中使用黄瓜版本 4 我在我的项目中使用以下依赖项。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ABCXYZ</groupId>
<artifactId>ABCXYZ</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ABCXYZ</name>
<url>http://maven.apache.org</url>
<build>
    
    <plugins>
    
    <!-- Plugin For Reporting  -->  
         <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>5.3.0</version>
            <executions>
            
                <execution>
                    <id>execution</id>
                    <phase>test</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>ABCXYZ</projectName>
                        <!-- optional, per documentation set this to "true" to bypass generation of Cucumber Reports entirely, defaults to false if not specified -->
                        <skip>false</skip>
                        <!-- output directory for the generated report -->
                        <outputDirectory>target/cucumber-report-html</outputDirectory>
                        <!-- optional, defaults to outputDirectory if not specified -->
                        <inputDirectory>${project.build.directory}</inputDirectory>
                        <jsonFiles>
                            <!-- supports wildcard or name pattern -->
                            <param>**/*.json</param>
                        </jsonFiles>
                        <!-- optional, defaults to outputDirectory if not specified -->
                        <classificationDirectory>${project.build.directory}</classificationDirectory>
                        <classificationFiles>
                                <!-- supports wildcard or name pattern -->
                                <param>sample.properties</param>
                                <param>other.properties</param>
                        </classificationFiles>
                        <parallelTesting>false</parallelTesting>
                        <!-- optional, set true to group features by its Ids -->
                        <mergeFeaturesById>false</mergeFeaturesById>
                        <!-- optional, set true to get a final report with latest results of the same test from different test runs -->
                        <mergeFeaturesWithRetest>false</mergeFeaturesWithRetest>
                        <!-- optional, set true to fail build on test failures -->
                        <checkBuildResult>false</checkBuildResult>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    
    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-M4</version>
      <configuration>
          <testFailureIgnore>true</testFailureIgnore>
     </configuration>
     <dependencies>  
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>3.0.0-M4</version>
        </dependency> 
    </dependencies>
    </plugin>
    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
        </plugin>                  
    </plugins>      
</build>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.2</version>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>index</report>
                        <report>license</report>
                        <report>project-team</report>
                        <report>distribution-management</report>
                        <report>dependancy-info</report>
                        <report>scm</report>
                        <report>issue-tracking</report>
                        <report>cim</report>
                        <report>summary</report>
                    </reports>
                    <configuration>
                        <linkonly>false</linkonly>
                    </configuration>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.141.5</version>
    </dependency>
    <dependency>
        <groupId>org.gdal</groupId>
        <artifactId>gdal</artifactId>
        <version>1.11.1</version>
    </dependency>   

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-project</artifactId>
        <version>2.2.1</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-annotations</artifactId>
        <version>3.6.0</version>
    </dependency>
    
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.12</version>
    </dependency>
    
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.2.3</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.6</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.2.3</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>4.2.3</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-server</artifactId>
         <version>3.0.1</version>
    </dependency> 
    
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>7.0.0</version>
    </dependency>
    
    <dependency>
         <groupId>commons-configuration</groupId>
         <artifactId>commons-configuration</artifactId>
         <version>1.10</version>
    </dependency>
    
    <dependency>
         <groupId>io.github.bonigarcia</groupId>
         <artifactId>webdrivermanager</artifactId>
         <version>4.1.0</version>
    </dependency>
    

    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
  
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.6.4</version>
   </dependency>

   <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.1.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

使用上述依赖项,我能够生成 'Cucumber jvm report'。

我也在java里写了代码,为了附上截图报告,我只在场​​景失败时截图。

@After
public void CloseBrowser(Scenario scenario) {
    if (scenario.isFailed()) {
        System.out.println("Scenario is Failled Taking ScreenShot...!!!");
        TakesScreenshot ts = (TakesScreenshot) driver;
        byte[] screenshot = ts.getScreenshotAs(OutputType.BYTES);
        scenario.embed(screenshot, "image/png");
    }
}

我不确定我是否遗漏了什么,但报告中没有附上屏幕截图。 Cucumber 生成的默认 html 报告显示屏幕截图。

有人可以帮我解决这个问题吗? 谢谢

你能检查截图是否嵌入了 html 报告的 After Hooks 步骤吗?这个 5.3.0 版本附上了 Hooks 步骤的截图,因为我们在 @After 中有我们的逻辑钩子。我也开始挣扎,后来才注意到这一点。