线程“main”中出现异常 java.lang.NoSuchMethodError: 'java.lang.ClassLoader[] org.apache.logging.log4j.util.LoaderUtil.getClassLoaders()'

问题描述 投票:0回答:1

以 testng 身份运行我的 selenium 代码时,出现上述错误。 下面是我的 pom.xml 文件。

这是完整的控制台日志 [RemoteTestNG] 检测到 TestNG 版本 7.9.0 线程“main”中出现异常 java.lang.NoSuchMethodError: 'java.lang.ClassLoader[] org.apache.logging.log4j.util.LoaderUtil.getClassLoaders()' 在 org.apache.logging.log4j.core.impl.ThreadContextDataInjector.getProviders(ThreadContextDataInjector.java:252) 在 org.apache.logging.log4j.core.impl.ThreadContextDataInjector.access$000(ThreadContextDataInjector.java:53) 在 org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForCopyOnWriteThreadContextMap。(ThreadContextDataInjector.java:192) 在org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:94) 在org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:71) 在 org.apache.logging.log4j.core.lookup.ContextMapLookup。(ContextMapLookup.java:34) 在 org.apache.logging.log4j.core.lookup.Interpolator。(Interpolator.java:126) 在 org.apache.logging.log4j.core.config.AbstractConfiguration。(AbstractConfiguration.java:129) 在 org.apache.logging.log4j.core.config.NullConfiguration。(NullConfiguration.java:32) 在 org.apache.logging.log4j.core.LoggerContext.(LoggerContext.java:86) 在 org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:233) 在 org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:206) 在 org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:131) 在 org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:118) 在 org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:148) 在 org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45) 在 org.apache.logging.log4j.LogManager.getContext(LogManager.java:196) 在 org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137) 在 org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:45) 在 org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47) 在 org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30) 在 org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363) 在 org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388) 在 org.testng.log4testng.Logger.lambda$getLogger$0(Logger.java:30) 在 java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) 在 org.testng.log4testng.Logger.getLogger(Logger.java:30) 在 org.testng.TestNG.(TestNG.java:111) 在 org.testng.remote.support.RemoteTestNGFactory7_8.createRemoteTestNG(RemoteTestNGFactory7_8.java:16) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:67)

<?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>FreeCRMTestAutomation</groupId>
  <artifactId>FreeCRMTest2</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>FreeCRMTest2</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

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

  <dependencies>
   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.18.0</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
    <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.2.5</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.5</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->

    <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.9.0</version>
    <scope>compile</scope>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/com.guicedee.services/sl4j -->
    <dependency>
    <groupId>com.guicedee.services</groupId>
    <artifactId>sl4j</artifactId>
    <version>1.0.13.5</version>
    </dependency>
    

<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>3.0.0-beta1</version>
</dependency>



  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

java maven selenium-webdriver
1个回答
0
投票

我找到了解决方案。出现这个错误是因为我下载的testng和maven依赖的testng版本不匹配。所以我更新了从 eclipse 市场下载的 testng 并且它起作用了。

© www.soinside.com 2019 - 2024. All rights reserved.