Search code examples
javaautomationaspectjallure

What could be the reason that no steps are displayed in Allure report with AspectJ weaving?


I'm currently working on an automation framework and the feature I am implementing right now is the possibility to log the messages on start and the end of the methods annotated with @Step from allure.

The issue is that I had a good-looking reports with steps described but whenever I tried to create some aspects I am missing all the Steps in my reports.

Currently thinking that the issue is connected maybe with AspectJ and Allure conflicts but I am entirely not sure what could be the exact issue. Maybe some of you are familiar with such issue and could point me in what direction to investigate since I've tried redesigning pom.xml file, disabling aop-ajc.xml file and whenever I delete my own aop.xml file the issue is not present but I cannot weave.

Here's my pom.xml file example:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>ATPW</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>22</maven.compiler.source>
        <maven.compiler.target>22</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <java.version>22</java.version>
        <playwright.version>1.41.2</playwright.version>
        <junit.version>5.10.2</junit.version>
        <allure.version>2.25.0</allure.version>
        <allure-maven.version>2.12.0</allure-maven.version>
        <allure-junit5.version>2.25.0</allure-junit5.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <aspectj.version>1.9.22</aspectj.version>
        <lombok.version>1.18.32</lombok.version>
        <log4j.version>2.23.1</log4j.version>
        <aspectj.version>1.9.22</aspectj.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.microsoft.playwright</groupId>
            <artifactId>playwright</artifactId>
            <version>${playwright.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit5</artifactId>
            <version>${allure.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.5</version>
                <configuration>
                    <properties>
                        <configurationParameters>
                            junit.jupiter.execution.parallel.enabled=true
                            junit.jupiter.execution.parallel.mode.default=concurrent
                        </configurationParameters>
                        <property>
                            <name>listener</name>
                            <value>io.qameta.allure.junit5.AllureJunit5</value>
                        </property>
                    </properties>
                    <systemProperties>
                        <property>
                            <name>allure.results.directory</name>
                            <value>${project.basedir}/target/allure-results</value>
                        </property>
                        <property>
                            <name>junit.jupiter.extensions.autodetection.enabled</name>
                            <value>true</value>
                        </property>
                    </systemProperties>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                    <argLine>
                        -javaagent:"${settings.localRepository}\org\aspectj\aspectjweaver\${aspectj.version}\aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-api</artifactId>
                        <version>${junit.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-engine</artifactId>
                        <version>${junit.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>${allure-maven.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
<!--            <plugin>-->
<!--                <groupId>dev.aspectj</groupId>-->
<!--                <artifactId>aspectj-maven-plugin</artifactId>-->
<!--                <version>1.14</version>-->
<!--                <dependencies>-->
<!--                    <dependency>-->
<!--                        <groupId>org.aspectj</groupId>-->
<!--                        <artifactId>aspectjtools</artifactId>-->
<!--                        <version>${aspectj.version}</version>-->
<!--                    </dependency>-->
<!--                </dependencies>-->
<!--                <configuration>-->
<!--                    <complianceLevel>22</complianceLevel>-->
<!--                    <showWeaveInfo>true</showWeaveInfo>-->
<!--                    <verbose>true</verbose>-->
<!--                    <encoding>UTF-8</encoding>-->
<!--                </configuration>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <goals>-->
<!--                            <goal>compile</goal>-->
<!--                            <goal>test-compile</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--            </plugin>-->
        </plugins>
    </build>
</project>

aop.xml example:

<aspectj>
    <weaver options="-verbose">
        <include within="test.java.*"/>
    </weaver>
    <aspects>
        <aspect name="utils.logging.LoggingAspect"/>
    </aspects>
</aspectj>

Only aspect class which I use:

package utils.logging;

import constants.LoggingMessage;
import io.qameta.allure.Step;
import org.aspectj.lang.annotation.*;
import org.junit.jupiter.api.DisplayName;

@Aspect
public class LoggingAspect {

    private static final String STEP_LOGGING_ANNOTATION_VALUE = "execution(* steps.*.*(..)) && @annotation(step)";
    private static final String TEST_LOGGING_ANNOTATION_VALUE = "execution(* tests.*.*(..)) && @annotation(displayName)";

    @Before(STEP_LOGGING_ANNOTATION_VALUE)
    public void logBeforeStep(Step step) {
        AllureLogger.info(String.format(LoggingMessage.StepsAction.STEP_EXECUTION_START, step.value()));
    }

    @After(STEP_LOGGING_ANNOTATION_VALUE)
    public void logAfterStep(Step step) {
        AllureLogger.info(String.format(LoggingMessage.StepsAction.STEP_EXECUTION_FINISH, step.value()));
    }

    @Before(TEST_LOGGING_ANNOTATION_VALUE)
    public void logBeforeTest(DisplayName displayName) {
        AllureLogger.info(String.format(LoggingMessage.TestsAction.TESTS_EXECUTION_START,
                displayName.value()));
    }

    @After(TEST_LOGGING_ANNOTATION_VALUE)
    public void logAfterTest(DisplayName displayName) {
        AllureLogger.info(String.format(LoggingMessage.TestsAction.TESTS_EXECUTION_FINISH,
                displayName.value()));
    }
}

Step class example:

import io.qameta.allure.Step;
import pageobjects.pages.HomePage;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HomeSteps {

    private final HomePage homePage = new HomePage();
    @Step("Hover over Left Side menu")
    public void hoverOverLeftSideMenu() {
        homePage.leftSidePanelForm.hoverOverHomeContainer();
    }
    @Step("Select Call Center option from the container")
    public void selectCallCenterOptionFromTheContainer() {
        homePage.leftSidePanelForm.clickCallCenterButton();
    }
    @Step("Verify Left Side menu is displayed")
    public void verifyLeftSideMenuIsDisplayed() {
        assertTrue(homePage.leftSidePanelForm.isHomeContainerDisplayed(),
                String.format(AssertMessage.ElementState.MENU_NOT_DISPLAYED, "Left Side", homePage.getName()));
    }
}

Report with AspectJ enabled

Report with AspectJ disabled


Solution

  • You must include the io.qameta.* package in your weaver configuration. Or you can replace the logging logic in your aspects with Test Lifecycle listeners provided by Allure.

    For proper Allure JUnit 5 configuration, please follow the official documentation.