首页 > 解决方案 > 宁静报告 - 屏幕截图不起作用

问题描述

我想在我的 Serenity 测试报告中添加屏幕截图,但它不适合我。生成报告但没有屏幕截图。我尝试了我发现的一切,但没有运气。有人可以帮我弄这个吗?

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <packaging>pom</packaging>

    <groupId>com.test</groupId>
    <artifactId>project</artifactId>
    <version>0.7</version>

    <modules>
        <module>../test-ui</module>
        <module>../commons</module>
    </modules>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.test.failure.ignore>true</maven.test.failure.ignore>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <serenity.version>2.4.0</serenity.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-junit</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.5</version>
        </dependency>


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

    </dependencies>


    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <environment>dev</environment>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
    </profiles>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>3.0.0-M1</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>lib/ojdbc7-12.1.0.1.jar</file>
                            <groupId>com.oracle</groupId>
                            <artifactId>ojdbc7</artifactId>
                            <version>12.1.0.1</version>
                            <packaging>jar</packaging>
                        </configuration>
                    </execution>
                </executions>
                <inherited>false</inherited>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
                <configuration>
                    <systemPropertyVariables>
                        <environment>${environment}</environment>
                        <browser>${browser}</browser>
                    </systemPropertyVariables>

                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.21.0</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <environment>${environment}</environment>
                        <browser>${browser}</browser>
                        <webdriver.driver>chrome</webdriver.driver>

                    </systemPropertyVariables>

                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.0.0-M3</version>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>failsafe-report-only</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <showSuccess>true</showSuccess>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>serenity-core</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>serenity-single-page-report</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>serenity-reports</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>

                </dependencies>
                <configuration>
                    <tags>${tags}</tags>
                    <reports>single-page-html</reports>
                </configuration>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

serenity.properties

webdriver.driver = provided
webdriver.provided.type = mydriver
webdriver.provided.mydriver = DriverFactory
thucydides.driver.capabilities = mydriver

serenity.take.screenshots=BEFORE_AND_AFTER_EACH_STEP
#serenity.take.screenshots=FOR_EACH_ACTION
#serenity.take.screenshots=AFTER_EACH_STEP
#serenity.take.screenshots=DISABLED
serenity.logging=VERBOSE

driverfactory.java 看起来像这样


public class DriverFactory  extends ThucydidesWebDriverSupport {

    @Managed
    public static WebDriver driver = null;

    public static WebDriver getDriver(){ return driver; }
...

测试从这个开始

    @Test
    @Screenshots(onlyOnFailures = true)
    @Title("Test")

我正在通过命令运行测试

mvn clean verify -Denvironment=dev -Dinjected.tags="browser:chrome"

生成报告但没有屏幕截图。

标签: javaserenity-bdd

解决方案


推荐阅读