4

说明说要将 environment.xml 添加到 Allure 结果目录(https://github.com/allure-framework/allure-core/wiki/Environment),但是这个文件夹会在 mvn clean 上被删除,所以文件会被删除. 有没有办法在每次构建时生成这个文件?

谢谢。

4

3 回答 3

7

只需通过maven 资源插件将您放入src/main/resources/并复制到您的结果目录或:mvn testmvn site

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-allure-environment</id>
            <phase>pre-site</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target/allure-results</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>environment.xml</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2015-07-17T15:24:51.200 回答
0

披露:我创建了处理此问题的 Java 库:https ://github.com/AutomatedOwl/allure-environment-writer

它使用 TransformerFactory 在测试的任何阶段将 environment.xml 写入 allure-results 路径。如果从清理的构建运行,它还会检查目录是否存在。

使用示例:

import static com.github.automatedowl.tools.AllureEnvironmentWriter.allureEnvironmentWriter;

public class SomeTests {

    @BeforeSuite
    void setAllureEnvironment() {
        allureEnvironmentWriter(
                ImmutableMap.<String, String>builder()
                        .put("Browser", "Chrome")
                        .put("Browser.Version", "70.0.3538.77")
                        .put("URL", "http://testjs.site88.net")
                        .build(), System.getProperty("user.dir")
                        + "/allure-results/");
    }

    @Test
    void someTest() {
        Assert.assertTrue(true);
    }
}
于 2018-12-03T12:58:14.663 回答
0

对我来说,“预站点”阶段没有工作正确的阶段是验证 我的资源在 src\test\java\resoruces 这是我的 pom.xml 文件中的工作答案

<plugin>
   <artifactId>maven-resources-plugin</artifactId>
   <version>3.1.0</version>
   <executions>
      <execution>
         <id>copy-resources</id>
         <phase>validate</phase>
         <goals>
            <goal>copy-resources</goal>
         </goals>
         <configuration>
            <outputDirectory>${basedir}/allure-results</outputDirectory>
            <resources>
               <resource>
                  <directory>src/test/resources</directory>
                  <includes>
                     <include>environment.xml</include>
                  </includes>
               </resource>
            </resources>
         </configuration>
      </execution>
   </executions>
</plugin> 
于 2018-11-10T17:19:55.383 回答