0

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

5
  • You mentioned AssertJ more than once, but did you mean AspectJ? Commented Jul 7 at 22:29
  • @StefanoCordio omg i am really sorry, probably was too tilted so didn't even notice. Yeah, I'm speaking about AspectJ :)
    – Vanadium
    Commented Jul 8 at 8:38
  • Welcome to SO. Please learn how to ask a question on SO and provide a minimal, complete, and verifiable example. Thank you. Specifically, you are asking an aspect question withozut presenting the aspect and the code it applies to. E.g., your target classes could be in a subpackage like test.java.something, which would make the aspect miss it, because test.java.* only matches this exact package. Subpackages can be matched with the double-dot notation test.java..*.
    – kriegaex
    Commented Jul 11 at 7:20
  • @kriegaex Hello, thank you for your comment, applied some changes to the question. Speaking of your last point, I probably didn't explain it well. Aspects are working but whenever I do use them, it seems like annotations on steps classes are getting lost so there's no steps in Allure report, so my question is more about the possible issue when using these two together.
    – Vanadium
    Commented Jul 11 at 9:08
  • Was anything unclear about the term MCVE before? Your project is incomplete and does not compile with the given POM. Please publish a minimal Maven reproducer on GitHub. Thank you.
    – kriegaex
    Commented Jul 13 at 11:41

1 Answer 1

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.