今天,我已经找到了一个很好的例子,说明了如何使用Selenium为web应用构建自己的测试自动化框架,以及如何轻松地理解代码和体系结构。这个例子演示了框架的使用。但是当我尝试用这个框架启动我的第一个简单示例时,我遇到了一个永久的问题。名字叫"NoClassDefFoundError“。
下一个是Stacktrace:
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)在当前的应用程序中,我使用Selenium 2.46 + Htmlelements 1.14 +最新的TestNG。此外,我还有更早的Htmlelements库(1.11)和Selenium2.48。我尝试用不同的库版本组合来启动我的示例。此外,我还使用了不同的方式对由适当类表示的html块进行注释,并使用以下方法对页面对象进行了非titi化
HtmlElementLoader.populatePageObject(this, driver);或
PageFactory.initElements(new HtmlElementDecorator(driver), this);这是在官方教程中提出的。但是结果总是一样的:我在调用上述方法时总是得到NoClassDefFoundError。
发布于 2015-10-21 21:16:57
发布于 2015-10-23 10:36:20
当依赖项中几乎没有相同库的不同不兼容版本时,NoClassDefFoundError通常会出现在maven项目中。在这种情况下,maven通常采用最古老的所需版本,这有时会带来这样的问题。有一些简单的步骤可以查找和修复问题:
mvn dependency:tree | grep your-problem-lib<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>https://stackoverflow.com/questions/33269061
复制相似问题