问题
My selenium automation framework using TestNG is working fine on the windows 7 but when I configured the same framework on the windows 10 I'm facing the below issue. Could you please help me on the same.
Test Details:
Operating system: windows 10 64 bit
Eclipse Version: Version: 2019-03 (4.11.0)
TestNG version: 6.14.3
[RemoteTestNG] detected TestNG version 6.14.3 org.testng.TestNGException: An error occurred while instantiating class com.saf.aw_nxt_end_to_end_tests.AW_NXT_Login: org/w3c/dom/ElementTraversal at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:435) at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336) at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125) at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190) at org.testng.internal.TestNGClassFinder.processFactory(TestNGClassFinder.java:203) at org.testng.internal.TestNGClassFinder.processMethod(TestNGClassFinder.java:179) at org.testng.internal.TestNGClassFinder.processClass(TestNGClassFinder.java:171) at org.testng.internal.TestNGClassFinder.(TestNGClassFinder.java:121) at org.testng.TestRunner.initMethods(TestRunner.java:370) at org.testng.TestRunner.init(TestRunner.java:271) at org.testng.TestRunner.init(TestRunner.java:241) at org.testng.TestRunner.(TestRunner.java:192) at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33) at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66) at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:713) at org.testng.SuiteRunner.init(SuiteRunner.java:260) at org.testng.SuiteRunner.(SuiteRunner.java:198) at org.testng.TestNG.createSuiteRunner(TestNG.java:1295) at org.testng.TestNG.createSuiteRunners(TestNG.java:1273) at org.testng.TestNG.runSuitesLocally(TestNG.java:1128) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) 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.NoClassDefFoundError: org/w3c/dom/ElementTraversal at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) at java.net.URLClassLoader.access$100(URLClassLoader.java:74) at java.net.URLClassLoader$1.run(URLClassLoader.java:369) at java.net.URLClassLoader$1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source) at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source) at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205) at org.apache.log4j.xml.DOMConfigurator$1.parse(DOMConfigurator.java:749) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:871) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:755) at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:896) at com.saf.utilities.Log.getInstance(Log.java:19) at com.saf.base.BaseTest.(BaseTest.java:138) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:24) at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423) ... 24 more Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 58 more Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:"C:\Program Files (x86)\HP\Unified Functional Testing\bin\java_shared\classes";"C:\Program Files (x86)\HP\Unified Functional Testing\bin\java_shared\classes\jasmine.jar"
回答1:
Looks like you are getting the java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
error.
From Another Answer:
The reason for this error is that the 1.4.01 version of the xml-apis library, includes the required ElementTraversal class. Other versions like 2.0.0, 1.0.0, etc. do not include it, and the application fails while compiling.
- MAVEN SOLUTION:
At pom.xml , set "xml-apis" dependency to version 1.4.01:
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
- SOLUTION FOR EVERYONE ELSE:
If not using maven, you can manually add the xml-apis library, version 1.4.01. You will find the jars inside the xml-commons binary package, named "XML Commons External 1.4.01", and you can download it here: http://xerces.apache.org/mirrors.cgi.
Finally, compile and execute your java application/project with this version of the library.
来源:https://stackoverflow.com/questions/55877440/org-testng-testngexception-an-error-occurred-while-instantiating-class