Allure: Environment file in target folder gets deleted on maven clean. How do I generate it on every build?

谁都会走 提交于 2019-12-10 10:03:38

问题


The instructions say to add the environment.xml to the Allure results directory (https://github.com/allure-framework/allure-core/wiki/Environment) but this folder gets deleted on mvn clean so the files gets deleted with it. Is there a way to generate this file on every build?

Thanks.


回答1:


Just put in in your src/main/resources/ and copy to your results directory via maven resources plugin on mvn test or mvn 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>



回答2:


for me, the phase "pre-site" didn't work the correct phase is validate my resources are on the src\test\java\resoruces here is a working answer from my pom.xml file

<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> 



回答3:


Disclosure: I've created Java library which deals with this issue: https://github.com/AutomatedOwl/allure-environment-writer

It uses TransformerFactory to write the environment.xml to the allure-results path in any stage of the test. It also checks for the directory existence in case running from cleaned build.

Usage example:

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);
    }
}


来源:https://stackoverflow.com/questions/31462784/allure-environment-file-in-target-folder-gets-deleted-on-maven-clean-how-do-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!