1

I am trying to create a TestNg Maven project in Eclipse for Selenium. Here is my code :

package Edureka_Case_Study_8th.Edureka_Case_Study_8th;

import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CaseStudy2 {
@Test
public void basicSetup() {
  System.setProperty("webdriver.gecko.driver", "C:\\Users\\Sitesh\\Selenium\\geckodriver.exe");
  WebDriver driver = new FirefoxDriver();
  driver.get("https://www.flipkart.com/ ");
}
}

When I try to run it, I get the following error:

[RemoteTestNG] detected TestNG version 7.3.0
FAILED: basicSetup
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/service/DriverService$Builder
at Edureka_Case_Study_8th.Edureka_Case_Study_8th.CaseStudy2.basicSetup(CaseStudy2.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(Unknown Source)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException:                                                           
org.openqa.selenium.remote.service.DriverService$Builder
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 29 more

Can anybody please come up with a suggestion / solution ?

Artifacts used : Eclipse - Version: 2020-06 (4.16.0) , Selenium - v3.141.59

1 Answer 1

1

Its look like issue is with Selenium Libraries. Please add all selenium jars. Follow below:

  1. Download Selenium Client & WebDriver Language Bindings for Java from (Make sure you are downloading as per your system configuration) https://www.selenium.dev/downloads/

  2. Unzip the file.

  3. Open your project > Right click > Build Path > Configure Built Path > Libraries > Add External Jars

  4. Select all jars present inside above unzipped folder ( Make sure you add libs also).

Also insure Java is installed and path for JDK is pointed under execution environment.

  1. Go to Build Path > Configure Built Path > Libraries.
  2. Open JRE System Libraries
  3. And if by default selected environment is not pointing to JDK. Select Alternate JRE.
  4. Click on Installed JREs and browse to JDK folder select.

Note : Using Same Code and above mentioned SetUp I am able to run your script.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help. After rechecking my libraries, I found that I had added 2 Selenium libraries in POM.xml. Keeping only one now, the script runs!
Happy to help. As you have not mentioned about that you are using Maven, i assumed you are adding jar files manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.