This is my first selenium script using TestNG and Maven. Created a simple \"Hello World\" code and a selenium test code which just checks the title of google page.
I was using eclipse 09-2019 which is the latest one with latest JDK installed 13, and latest selenium jar files 3.141.59, I installed other JDKs to work around to solve this issue after trying all answers on similar question. Then after 4 days trying, installed eclipse neon version(https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/neon/3/eclipse-java-neon-3-win32-x86_64.zip&mirror_id=105) and used Selenium-Java 3.5.2 jar files (https://jar-download.com/artifacts/org.seleniumhq.selenium/selenium-java/3.5.2/source-code) and now it is working perfectly Alhamdullilah. Also I don't know what was the errors root cause exactly or at all, but now it is solved. Wish if that help You
NoClassDefFoundError in Java occurs when JVM 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 runtime then JVM will throw NoClassDefFoundError.
The error you are seeing is :
java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
This clearly indicates that Selenium
is trying to resolve the particular FirefoxDriver Class at runtime from org/openqa/selenium/firefox/FirefoxDriver
which is not available.
This situation occurs if there are presence of multiple sources to resolve the Classes and Methods through JDK
/Maven
/Gradle
.
From the pom.xml it is pretty clear that you have added multiple dependencies for FirefoxDriver Class as follows:
<artifactId>selenium-java</artifactId>
:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<artifactId>selenium-firefox-driver</artifactId>
:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.12.0</version>
</dependency>
<artifactId>selenium-server</artifactId>
:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.12.0</version>
</dependency>
Additionally you have also added all jar files.
From all the above mentioned points it's clear that the related Class
or Methods
were resolved from one source at Compile Time which was not available during Run Time.
Here are a few steps to solve NoClassDefFoundError :
pom.xml
) to resolve the Classes and Methods.<artifactId>selenium-java</artifactId>
or <artifactId>selenium-server</artifactId>
. Avoid using both at the same time.pom.xml
While you execute a Maven Project always perform the folling in sequence:
maven clean
maven install
maven test
You can find related discussions in: