Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically build allure report after test completion

I am trying to figure out how to automatically build the allure report after my TestNG suite has completed. I know its possible to create the report by running mvn site manually after the test, but it would be great if it was possible for the reports to be automatically be generated. Below is the allure config from my pom.xml

                <properties>
                  <testng.congig>${selenium.suite}</testng.congig>
                  <aspectj.version>1.7.4</aspectj.version>
                  <allure.version>1.4.3</allure.version>
                </properties>

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14</version>
                <configuration>
                    <testFailureIgnore>false</testFailureIgnore>
                    <argLine>
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                    <suiteXmlFiles>
                        <suiteXmlFile>target\test-classes\${testng.congig}</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

            <dependency>
              <groupId>ru.yandex.qatools.allure</groupId>
              <artifactId>allure-testng-adaptor</artifactId>
              <version>${allure.version}</version>
           </dependency>

           <reporting>
             <excludeDefaults>false</excludeDefaults>
             <plugins>
              <plugin>
                 <groupId>ru.yandex.qatools.allure</groupId>
                 <artifactId>allure-maven-plugin</artifactId>
                 <version>{latest.version}</version>
               </plugin>
             </plugins>
           </reporting>
like image 763
Cathal Avatar asked Sep 08 '25 03:09

Cathal


2 Answers

The test execution and site generation run in a different life cycle.

The default lifecycle differs from the site lifecycle, see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

What you can do is just chain the commands: e.g. mvn install site or mvn deploy site-deploy if you plan to make the site available somewhere. This will run the tests and then execute a site generation.

The maven goals relate to a phase in that lifecycle. mvn package will execute all plugins bound to one of the phases until package phase. Since site generation has its own lifecycle I would not bind the plugin execution to one of the phases of the default lifecycle. Reporting plugins often rely on a finished build.

like image 118
wemu Avatar answered Sep 09 '25 23:09

wemu


Step 1. Add dependencies Allure Builder Reporter into pom.xml https://mvnrepository.com/artifact/ru.yandex.qatools.allure/allure-report-builder/2.1

Step 2: Add this code:

// It will generate the Allure Report folder.
  new AllureReportBuilder("1.5.4", new File("target/allure-report")).unpackFace();
  new AllureReportBuilder("1.5.4", new File("target/allure-report")).processResults(new 
  File("target/allure-results"));
like image 42
Rahul Jain Avatar answered Sep 09 '25 22:09

Rahul Jain