If you are using selenium web driver with maven-surefire-plugin, you might be aware of the fact that test run report are overwritten with the latest report in \target\surefire-reports\html folder. If you would like to refer to the past run reports, you may end up writing code to copy reports into the folder you want. Today I would like to share with you a easy to achieving the same using copy-maven-plugin.

Please follow the below steps:

1) Open you pom.xml file

2) Add the following property tag
<properties>
    <maven.build.timestamp.format>yyyy-MM-dd_HH-mm-ss </maven.build.timestamp.format>
  </properties>

3) Add the below lines under <plugins> tag.

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>copy-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>create-archive</id>
            <phase>test</phase>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <resources>
                    <!-- ~~~~~~~~~~~~~~ -->
                    <!-- Copy directory -->
                    <!-- ~~~~~~~~~~~~~~ -->
                    <resource>
                         <targetPath>${basedir}/your target path/rep_${maven.build.timestamp}</targetPath>
                         <directory>${basedir}/target/surefire-reports/html</directory>
                    </resource>
                 </resources>
            </configuration>
        </execution>
    </executions>
    </plugin>

Thats it, you are done. Now after each and every test run, reports will be saved in the folder you want with time stamp appended.

Try this if you have not tried it yet. Happy testing...:-)