Friday, October 28, 2011

No Class Definition Found Error in Eclipse

If we want to run Selenium Java code from Eclipse, we need to include the following jar files in our class path.

1) selenium-java-2.x.jar (Java Client Driver)
2) JUnit-4.x.jar or TestNG.jar (Testing Framework)

These two files are enough for executing our Selenium Automation scripts. Sometimes we might get the below error while executing the script. In this scenario, we need to include our selenium server jar file in the class path which will fix this issue. I have experienced this issue several times and this solution has fixed my problem. Please try this.

selenium-standalone-server-2.x.jar


Expected Error:

java.lang.NoClassDefFoundError: com/google/common/base/Charsets

at com.thoughtworks.selenium.HttpCommandProcessor.getOutputStreamWriter(HttpCommandProcessor.java:138)
at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:165)
at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:108)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:90)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:266)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:227)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:82)
at com.eviltester.seleniumtutorials.PlacedOrder_final.setUp(PlacedOrder_final.java:12)
at junit.framework.TestCase.runBare(TestCase.java:132)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:228)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Charsets
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 23 more

No comments:

Post a Comment