i have a simple Selenium Test Code:
public static void main(String[] args) {
System.setProperty(\"webdriver.chrome.driver\", \"/home/chromedriver\");
The error says it all :
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/ConnectionPool | Caused by: java.lang.ClassNotFoundException: okhttp3.ConnectionPool
NoClassDefFoundError
NoClassDefFoundError
in Java occurs when Java Virtual Machine
is not able to find a particular class at runtime which was available at compile time. For example, if we have resolved a method call from a class or accessing any static member of a Class and that Class is not available during run-time then JVM
will throw NoClassDefFoundError
.
The error clearly says that you have misconfigured the classpath. It would be tough to debug the exact cause of the issue untill and unless you tell us how you run tests, which builder or IDE do you use and the builder config file or project description.
From all the above mentioned points it's clear that the related Class
or Methods
were resolved from one source Compile Time
which was not available during Run Time
.
This situation occurs if there are presence of multiple sources to resolve the Classes and Methods through JDK
/Maven
/Gradle
.
At this point it is worth to mention that selenium-java-3.9.x clients does have a dependency on okhttp and you can find the dependency list here.
It is also to be noted that :
There were some issues with launching of Chrome as per Can't launch chrome browser using latest selenium 3.9.0.
To address the issue from Selenium v3.9.1 OkHttp backed instances can now connect to servers requiring authorisation which was based on PR #5444.
Here are a few steps to solve NoClassDefFoundError - okhttp3/ConnectionPool
error :
Maven
or Gradle
, remove all the External JARs
from the Java Build Path
. Maven
or Gradle
will download and resolve all the required dependencies.Selenium JARs
within a Java Project
add only required External JARs
within the Java Build Path
and remove the unused one.Maven
, either use selenium-java
or selenium-server
. Avoid using both at the same time.@Test
.