说明指出要将environment.xml添加到Allure结果目录(https://github.com/allure-framework/allure-core/wiki/Environment),但是此文件夹在mvn clean上被删除,因此文件将被删除。有没有办法在每次构建时生成此文件?
感谢。
答案 0 :(得分:7)
只需输入您的src/main/resources/
并通过mvn test
或mvn site
上的maven resources plugin复制到您的结果目录:
<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>
答案 1 :(得分: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>
答案 2 :(得分:0)
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);
}
}