4

我希望更改 Serenity 报告中的 CSS 和徽标。此外,我想在 Serenity 报告中添加一些自定义文本或一些测试的链接。就像生成了一个 excel 报告,我希望在报告的测试步骤中提供它的链接。实现这一目标的最佳方法是什么?

4

2 回答 2

5

I found a better and cleaner way to customise the Serenity reports. Basically, we can generate our own Serenity-reports-resources project with a different version number and configure our project to use our customised reports resources build instead of the official reports resources. The setps to do this are as follows:

  1. Download sources from:

    https://github.com/serenity-bdd/serenity-core.git

  2. Modify build Gradle settings to generate your own "serenity-report-resources" jar file. Open the "build.gradle" file. 2.1 Add "mavenLocal()" to the repositories:

    buildscript {
        repositories {
            mavenLocal()
            .....

    2.2 Add Maven publish plugin

    apply plugin: 'maven-publish'

    2.3 Change the subproject version number. Replace the line:

    version = rootProject.version

    for

    version = '0.0.0.1'

    Note: use the version number that you want in order to track changes of your reporting site.

  3. Run

    mvn clean build
    for the subproject "serenity-report-resources"

    3.1 Run

    publishing / publishToMavenLocal
    to install your reporting site as a new maven dependency in the local repository. Publish or deploy this build where you need it when running test in other environments.

  4. Configure your project to not include the official "serenity-report-resources" dependency and add yours instead.

4.1 In the dependencies section add the serenity-core without the reports.

<dependency>
    <groupId>net.serenity-bdd</groupId>
    <artifactId>serenity-core</artifactId>
    <version>${serenity.version}</version>
    <exclusions>
        <exclusion>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-report-resources</artifactId>
        </exclusion>
    </exclusions>
</dependency>

4.2 Add your custom reports dependency. Use the same version number that you used before.

<dependency>
    <groupId>net.serenity-bdd</groupId>
    <artifactId>serenity-report-resources</artifactId>
    <version>0.0.0.1</version>
</dependency>

4.3 Configure the serenity plugin dependencies to use your custom reports build.

<!-- Serenity plugin -->
<plugin>
    <groupId>net.serenity-bdd.maven.plugins</groupId>
    <artifactId>serenity-maven-plugin</artifactId>
    <version>${serenity.maven.version}</version>
    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>net.serenity-bdd</groupId>
                    <artifactId>serenity-report-resources</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-report-resources</artifactId>
                <version>0.0.2</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>serenity-reports</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Now when you run tests with the "SerenityRunner" it should find the resources of your custom reports build instead of the official serenity reports build.

It would be better if we could just configure the location of resources needed to generate reports as static or system property from the same framework. Let see what I can do :-)

I hope it helps, Keep on hacking

于 2018-02-02T09:38:34.737 回答
3

自定义 CSS 和图像的一种 hacky 方法是使用 Maven 资源插件,如下所示。

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>copy-web.xml</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${basedir}/target/site/serenity/images</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources/images</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

在“src/main/resources/images”中调整您的图像。即您的徽标名称为“serenity-logo.png”,因为 HTML 代码具有此名称。您也可以添加 CSS 文件以及要替换的 CSS 文件的相对路径。

运行测试后,只需运行命令“mvn process-resources”。这将替换文件,然后您将拥有一个自定义图像和 CSS 文件的站点。

这不是最好的解决方案,但可以快速解决您的报告的外观。

于 2018-01-29T09:50:18.930 回答