I have a UI automation framework that uses AspectJ for various purposes like logging steps, taking screenshots, etc. It is a maven project and uses TestNG, Selenium, etc as dependencies. Now, the problem is, When I try to run an individual test from IDE the classes with @Aspect annotation are not executing at all but when I use mvn test
command it executes as expected. This behavior started when I updated the java version from 8 to 11 otherwise previously it was working fine no matter how I executed the test. I suspect it is caused by some discrepancies in dependencies so I have included my pom.xml file.
My test codes are as follows.
pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenium.version>4.7.1</selenium.version>
<jdk.version>11</jdk.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven-compiler.version>3.8.0</maven-compiler.version>
<suiteDir>suites</suiteDir>
<suite>onlyOneClassSample.xml</suite>
<aspectj.version>1.9.19</aspectj.version>
<allure.version>1.4.0</allure.version>
<testng.version>7.7.0</testng.version>
<commons-configuration.version>1.10</commons-configuration.version>
<com.oracle.version>10.2.0</com.oracle.version>
<fest-assert.version>1.4</fest-assert.version>
<joda-time.version>2.12.2</joda-time.version>
<slf4j-api.version>2.0.5</slf4j-api.version>
<slf4j-log4j12.version>2.0.5</slf4j-log4j12.version>
<log4j-core.version>2.19.0</log4j-core.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
<aspectjrt.version>1.9.19</aspectjrt.version>
<reportng.version>1.1.4</reportng.version>
<groovy-all.version>2.4.21</groovy-all.version>
<extentreports.version>5.0.9</extentreports.version>
<commons-io.version>2.11.0</commons-io.version>
<javax.mail.version>1.6.2</javax.mail.version>
<javax.mail-api.version>1.6.2</javax.mail-api.version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>${commons-configuration.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>${fest-assert.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-core.version}</version>
</dependency>
<!--Dependency for allure test framework-->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectjrt.version}</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>${reportng.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy-all.version}</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>${extentreports.version}</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>${javax.mail-api.version}</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.6.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.0-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.advalent.automation.impl.component.webelement.CustomElementInitializer</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>
--illegal-access=permit
</argLine>
<suiteXmlFiles>
<suiteXmlFile>${suiteDir}/${suite}</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>${project.build.directory}/testngReports/${suite}</reportsDirectory>
<!--Load Time Weaving-->
<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>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
</plugin>
</plugins>
</build>
Any help will be greatly appreciated . Please help me find what is causing @Aspect to not work as aspected.
I can attach other codes as well if needed.
I updated the Intelli j version to 2022 and it fixed the issue.