selenium @Aspect类在从intelli j运行individual测试时不执行,但在运行mvn测试时执行

q8l4jmvw  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(144)

我有一个UI自动化框架,它使用AspectJ来实现各种目的,比如记录步骤、截图等。这是一个maven项目,使用TestNG、Selenium等作为依赖项。现在,问题是,当我尝试从IDE运行单个测试时,带有@Aspect注解的类根本不执行,但当我使用mvn test命令时,它按预期执行。当我把java版本从8升级到11时,这个问题就开始了,否则以前无论我如何执行测试,它都能正常工作。我怀疑这是由依赖关系中的一些差异引起的,所以我包含了我的pom.xml文件。我的测试代码如下所示。

属性值.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>

任何帮助都将不胜感激。请帮助我找到导致@Aspect无法工作的原因。
如果需要,我也可以附加其他代码。

vjrehmav

vjrehmav1#

我将Intelli J版本更新到2022年,它修复了这个问题。

相关问题