Allure: Environment file in target folder gets del

2019-05-11 16:50发布

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.

3条回答
beautiful°
2楼-- · 2019-05-11 17:09

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楼-- · 2019-05-11 17:18

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);
    }
}
查看更多
Root(大扎)
4楼-- · 2019-05-11 17:21

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>
查看更多
登录 后发表回答