Allure 结果不会在 Maven 构建上生成

问题描述 投票:0回答:4

我正在使用 Maven 运行 Selenium 测试,并希望最终生成一份 Allure 报告。不幸的是,我收到一条错误消息。

Maven 命令行:

clean -Dtest=TestLogs test allure:report

错误信息:

[INFO] --- allure-maven:2.9:report (default-cli) @ demo ---
[INFO] Allure installation directory C:\Users\Zoe\Documents\demo\selenium_tests\demo_selenium/.allure
[INFO] Try to finding out allure 2.3.1
[INFO] Generate Allure report (report) with version 2.3.1
[INFO] Generate Allure report to C:\Users\Zoe\Documents\demo\selenium_tests\demo_selenium\target\site/allure-maven-plugin 
[ERROR] Directory C:\Users\Zoe\Documents\demo\selenium_tests\demo_selenium\target\target\allure-results not found.
[WARNING] Allure report was skipped because there is no results directories found.

我的 POM.xml:

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

<modelVersion>4.0.0</modelVersion>

<groupId>org.wesh.nc</groupId>
<artifactId>demo</artifactId>
<!--<packaging>pom</packaging>-->
<packaging>jar</packaging>
<version>1.0</version>

<properties>
    <allure.version>1.5.2</allure.version>
    <allure.maven.version>2.0</allure.maven.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.20.1</version>
            <configuration>
                <skip>${skip.selenium.tests}</skip>
                <parallel>none</parallel>
                <threadCount>1</threadCount>
                <reuseForks>false</reuseForks>
                <disableXmlReport>false</disableXmlReport>
            </configuration>
            <executions>
                <execution>
                    <id>runSeleniumTests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.9</version>
            <configuration>
                <resultsDirectory>target\allure-results</resultsDirectory>
                <inputDirectories>target\allure-results</inputDirectories>
                <outputDirectory>target\allure-report</outputDirectory>
                <reportVersion>2.3.1</reportVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-maven-plugin</artifactId>
            <version>${allure.maven.version}</version>
            <configuration>
                <resultsPattern>target\allure-results</resultsPattern>
                <outputDirectory>target\target-report</outputDirectory>
            </configuration>

            <executions>
                <execution>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.7</version>
    </dependency>
    <dependency>
        <groupId>org.gebish</groupId>
        <artifactId>geb-core</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.gebish</groupId>
        <artifactId>geb-spock</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.0-groovy-2.4</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>3.8.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>3.8.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.8.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>pl.pragmatists</groupId>
        <artifactId>JUnitParams</artifactId>
        <version>1.1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.6</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-maven-plugin</artifactId>
        <version>${allure.maven.version}</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-junit-adaptor</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-commons</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-report-data</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-java-adaptor-api</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-model</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
</dependencies>

<reporting>
    <excludeDefaults>true</excludeDefaults>
    <plugins>
        <plugin>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-maven-plugin</artifactId>
            <version>${allure.maven.version}</version>
            <configuration>
                <outputDirectory>target/allure-report</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
</reporting>

我知道这个 POM 很混乱,为了让 Allure 工作,我一直在尝试一些事情......

如果有人知道我可以做什么来生成 allure-results 目录,请提前致谢。

java maven selenium junit allure
4个回答
4
投票

您错过了 Allure 侦听器和 AspectJ 配置。请按照文档页面的说明进行操作:https://github.com/allure-framework/allure1/wiki/JUnit

您也可以考虑升级到最新的 Allure 版本。新版本的文档可以在这里找到https://docs.qameta.io/allure/#_junit_4


0
投票

将 Aspect 更新到最新版本解决了我的问题


0
投票

我在同一问题上花了太多时间,在与 chatGPT 进行长时间交谈后,我发现以下问题没有创建 allure-results 文件夹

我的 pom.xml 中已经有以下配置,但它没有生成 allure-结果。

构建标签内maven-surefire插件下的配置

` <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>

                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testNG.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <systemPropertyVariables>
                        <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
                    </systemPropertyVariables>
                </configuration>
                <dependencies>
                     <dependency>
                         <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>`

其他依赖项如下

  <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-attachments</artifactId>
        <version>2.13.8</version>
    </dependency>

    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-java-commons</artifactId>
        <version>2.15.0</version> <!-- Replace with the desired version -->


 </dependency>



 <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${testng-version}</version>
    </dependency

但这并没有解决我的 testNG + Maven + Selenium + Java + Allure Setup 中的问题。在研究了太多的博客、链接、ChatGPT 后,我发现我遗漏了 2 件重要的事情。 TestNG.xml 中的 allureTestNG 监听器

  <suite name="automation">
    <listeners>
        <listener class-name="io.qameta.allure.testng.AllureTestNg"/>
    </listeners>

allure-maven 插件

`   <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>2.10.0</version>
                <configuration>
                    <reportVersion>2.14.0</reportVersion>
                </configuration>
            </plugin>

`

现在运行

mvn clean test
,我的魅力结果正在您的pom.xml中提到的所需位置生成,我可以简单地编写另一个命令

allure generate target/allure-results
allure open 

还有宾果游戏!!

美丽的诱惑:)在那里

enter image description here

如果您不使用监听器和我上面提到的其他插件,则不会生成 allure-results 文件夹

您将尝试使用以下命令生成 allure-report 文件夹

allure generate target/surefire-reports 
allure open 

但是现在打开的报告的描述性会稍差一些,并且不会包含许多重要方面,例如@step详细信息。样本如下 看看差异。

enter image description here

希望有帮助!!


0
投票

我扫描了配置,发现你漏掉了两件事。

  1. 在 testng.xml 文件中添加监听器。
  2. 在pom.xml文件中添加依赖

运行测试用例:

© www.soinside.com 2019 - 2024. All rights reserved.