NoClassDefFoundError with chromedriver



当我尝试使用chromedriver:运行测试时,会出现此错误

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException:无法完成gradle测试执行器30的执行。网址:org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)在java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)在java.base@16.0.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在java.base@16.0.1/java.lang.reflect.Method.ioke(Method.java:567)网址:org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDisptch.java:36)网址:org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDisptch.java:24)位于org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)位于org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)位于jdk.proxy1/jdk.proxy1.$Proxy2.stop(未知源)网址:org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)位于org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintaineThreadName(TestWorker.java:129)网址:org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)网址:org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)位于org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)网址:org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoader worker.java:133)网址:org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoader worker.java:71)位于app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorker Main.java:69)位于app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorker main.java:74)由以下原因引起:org.unit.platform.commons.JUnitException:ID为"junit jupiter"的测试引擎未能发现测试位于org.junit.platform.selauncher.core.EngineDiscoveryOrchestrator.decoveryEngineRoot(EngineDiscoveryOrhestrator.java:111)位于org.junit.platform.selauncher.core.EngineDiscoveryOrchestrator.decover(EngineDiscoveryOrhestrator.java:85)网址:org.junit.platform.selauncher.core.DefaultLauncher.discover(DefaultLauncher.java:92)位于org.junit.platform.selauncher.core.DefaultLauncher.execute(DefaultLauncher.java:75)网址:org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasss(JUnitPlatformTestClassProcessor.java:99)网址:org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)网址:org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)网址:org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)…还有18个由:org.unit.platform.commons.JUnitException引起:ClassSelector[className='com.paulcarron.learningspringboot.learningspring boot.EndToEndTests']解析失败位于org.junit.platform.selauncher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnfailureLauncheriscoveryListener.java:39)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequest Resolution.java:102)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequest Resolution.java:82)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequest Resolver.java:113)网址:org.junit.jupiter.engine.discovery.DiscoverySelector.resolveSelectors(DiscoverySelector.java:45)网址:org.junit.jupiter.engine.JupiterTestEngine.decover(JupiterTestEngine.java:69)位于org.junit.platform.selauncher.core.EngineDiscoveryOrchestrator.decoveryEngineRoot(EngineDiscoveryOrhestrator.java:103)…还有25个引起原因:java.lang.NoClassDefFoundError:org/openqa/selement/WebDriver位于java.base/java.lang.Class.getDeclaredMethods0(本机方法)位于java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3334)位于java.base/java.lang.Class.privateGetPublicMethods(Class.java:3359)位于java.base/java.lang.Class.getMethods(Class.java:1990)位于org.junit.platform.commons.util.ReflectionUtils.getDefaultMethods(ReflectionUtils.java:1481)网址:org.junit.platform.commons.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:1454)网址:org.junit.platform.commons.util.ReflectionUtils.findMethod(ReflectionUtils.java:1304)网址:org.junit.platform.commons.util.ReflectionUtils.isMethodPresent(ReflectionUtils.java:1205)网址:org.junit.jupiter.engine.discovery.verbers.IsTestClassWithTests.hasTestOrTestFactoryOrTestTemplateMethods(IsTestClassWithTests.java:50)网址:org.junit.jjupiter.engine.discovery.verbers.IsTestClassWithTests.test(IsTestClassWithTests.java:46)网址:org.junit.jupiter.engine.discovery.ClassSelectorResolve.resolve(ClassSelectorResolver.java:67)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequest Resolution.java:134)位于java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePiperine.java:197)位于java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602)位于java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePiperine.java:129)位于java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)位于java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)位于java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)位于java.base/java.util.stream.FindOps$FindOp.evalateSequential(FindOps.java:150)位于java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)位于java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePiperine.java:647)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequest Resolution.java:185)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequest Resolution.java:125)网址:org.junit.platform.engine.support.decovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequest Resolution.java:91)…还有30个引起原因:java.lang.ClassNotFoundException:org.openqa.selenium.WebDriver位于java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)位于java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)位于java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)…还有54个

我将chromedriver部署到ext文件夹中,并拥有适用于我的浏览器的正确版本。是什么导致了这个问题?它似乎来自@BeforeClass,如下所示:

@BeforeClass
public static void setUp() throws IOException {
System.setProperty("webdriver.chrome.driver", "ext/chromedriver");
service = createDefaultService();
driver = new ChromeDriver(service);
Path testResults = Paths.get("build", "test-results");
if (!Files.exists(testResults)) {
Files.createDirectory(testResults);
}
}

NoClassDefFoundError

NoClassDefFoundError发生在JVM在运行时找不到编译时可用的特定类时。例如,如果我们解析了来自类或访问类的任何静态成员的方法调用,而该类在运行时不可用,则JVM将抛出NoClassDefFoundError

您看到的错误是:

java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver at java.base/java.lang.Class.getDeclaredMethods0(Native Method)

这清楚地表明Selenium正试图在运行时从不再可用的org/openqa/selenium/WebDriver解析特定类。


解决方案:

System.setProperty()行中,您需要通过ChromeDriver的绝对路径,如下所示:

System.setProperty("webdriver.chrome.driver", "/complete/path/to/chromedriver");

参考文献

您可以在中找到一些相关的详细讨论

  • 线程中的异常";主";java.lang.NoClassDefFoundError:org/openqa/selement/WebDriver
  • Selenium TestNG Maven-Getting;java.lang.NoClassDefFoundError:org/openqa/selenium/firefox/FirefoxDriver">
  • java.lang.NoClassDefFoundError:com/google/common/collection/InmutableMap错误,通过java中的Selenium使用GeckoDriver Firefox

相关内容

  • 没有找到相关文章

最新更新