0

Today I've found nice example of how to build own test automation framework for web apllication using Selenium Webdriver, and get nice and easy understanding code and architecture. This example demonstrated using of Yandex Htmlelements framework. But when I tried to launch my first simple example with this framework, I've got one permanent problem. It's name "NoClassDefFoundError".

Stacktrace is next:

java.lang.NoClassDefFoundError: org/apache/commons/lang/WordUtils
at ru.yandex.qatools.htmlelements.utils.HtmlElementUtils.splitCamelCase(HtmlElementUtils.java:134)
at ru.yandex.qatools.htmlelements.utils.HtmlElementUtils.getElementName(HtmlElementUtils.java:121)
at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator.decorate(HtmlElementDecorator.java:60)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:112)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:104)
at calculator.MainPage.<init>(MainPage.java:18)
at calculator.Test1.Test(Test1.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.WordUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

In current application I use Selenium 2.46 + Htmlelements 1.14 + Latest TestNG. Also I have earlier Htmlelements library (1.11) and Selenium 2.48. I tried to launch my example with different combinations of libraries versions. Also I used different ways for annotation of my html blocks represented by appropriate classes, and intialize my page object using such methods as

HtmlElementLoader.populatePageObject(this, driver);

or

PageFactory.initElements(new HtmlElementDecorator(driver), this);

which are suggested in oficial tutorials. But result is always the same: I always get NoClassDefFoundError on invokation of above methods.

Sančiezz
  • 81
  • 2
  • 11

2 Answers2

0

You are missing the commons-lang package on your classpath. If you use a dependency manager like maven this will be taken care of for you, otherwise download the jar and add it to your lib folder.

joostschouten
  • 3,863
  • 1
  • 18
  • 31
  • BINGO! Thank you very much! The latest version contains next package org.apache.commons.lang3.* without WordUtils class. So for successful class initialization we should download 2.6, the latest library version with this class in ...lang package. – Sančiezz Oct 21 '15 at 22:09
0

NoClassDefFoundError usually appears in maven projects when you have few different uncompatible versions of the same library in your dependencies. In this case maven usually takes oldest of required versions which sometimes brings such problems. There are simple steps to find and fix problem:

  1. Find out library where missed class belongs (simply by googling full class name)
  2. Use maven dependency plugin to build full dependency tree and find where conflicting versions are coming from: mvn dependency:tree | grep your-problem-lib
  3. Exclude conflicting versions from your dependecies, e.g.: <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>3.2.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>cglib</groupId> <artifactId>cglib</artifactId> </exclusion> </exclusions> </dependency>
artkoshelev
  • 872
  • 7
  • 22