0

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.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
CodeBlooded
  • 185
  • 5
  • 16
  • Please provide a full sample project (ideally on GitHub), not just a fragmentary Maven POM. Generally, please learn [how to ask a question on SO](https://stackoverflow.com/help/how-to-ask) and provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). Thank you. Please also mention your IDEA version (Ultimate or Community, version no.) and tell us, which aspect-related plugins you installed. – kriegaex Jan 12 '23 at 09:54
  • @krieraex, I appreciate you eagerly trying to answer my question, but there is nothing harm in using some kind word to ask for more details. I have already mentioned in my question that I will add other codes if needed. As for the delay in response, I was occupied with another task. And I don't think I need to remind you that the main jest of using Stack overflow is to ask questions without being judged. So, next time please be kind to others. Thank you.. For my problem, I changed the IntelliJ version, and it is fixed. – CodeBlooded Jan 24 '23 at 16:53
  • Where was I unkind? I took time to guide you towards writing better questions for your own benefit: to get better answers faster. And no, it is not the main purpose of Stack Overflow to ask without being judged. It is a platform to ask for and get help, where the people who ask should first and foremost respect the time budgets of volunteers who help them for free in their sparetime by asking as precisely as possible and making it maximally easy to reproduce their problems quickly. – kriegaex Jan 24 '23 at 20:20
  • @kriegaex, in the comment, that you deleted. Man... seems like you have a lot of time to argue on such insignificant matters with strangers. – CodeBlooded Jan 31 '23 at 07:16
  • I did not delete any comments. Maybe it was deleted by a moderator. Look, I do not want to be unkind, but you are unexperienced here and asking questions in a way which is not helpful for yourself or others trying to help you. Yes, I do take time to comment on suboptimal questions, because I also take time to answer them. I could answer 5x more questions and help more people, if I would not have to ask for obviously missing details in 80% of all cases. The people who accept my advice benefit the most by getting correct answers quickly. Some actually learn and improve the way they ask. – kriegaex Jan 31 '23 at 13:14

1 Answers1

0

I updated the Intelli j version to 2022 and it fixed the issue.

CodeBlooded
  • 185
  • 5
  • 16