0

我在 Java 中使用 RED 机器人框架编辑器。虽然我添加了包含“com/github/markusbernhardt/selenium2library/utils/WebDriverCache”的 jar 文件,但它错误为“NoClassDefFoundError”

我使用robotframework-selenium2library-java-1.4.0.8 来创建java 库。

下面是在 RED 编辑器中生成的控制台命令。

Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Java\JarsKCC\Misc.jar;C:\Java\JarsKCC\KCCUtils.jar;C:\Java\JarsKCC\GetElementList.jar;C:\jython2.7.0\selenium-server-standalone-3.3.1.jar;C:\jython2.7.0\robotframework-selenium2library-java-1.4.0.8 -m robot.run -P C:\jython2.7.0\Lib\site-packages\Selenium2Library --listener C:\Users\CON_RT~1\AppData\Local\Temp\RobotTempDir2533122362618779828\TestRunnerAgent.py:56178:False -s KCC_Automation.TestSuites.TestSeparateWebdriverInstance C:\Java\Workspace\KCC_Automation
Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_121)

执行时收到错误,

[ ERROR ] Unexpected error: NoClassDefFoundError: 
com/github/markusbernhardt/selenium2library/utils/WebDriverCache
java.lang.NoClassDefFoundError: 
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at robot.utils.importer$py.import_$32(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py:274)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py)
at robot.utils.importer$py._import_class_or_module$5(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py:77)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py)
at robot.utils.importer$py.import_class_or_module$4(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py:74)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py)
at robot.model.itemlist$py.visit$11(C:\jython2.7.0\Lib\site-packages\robot\model\itemlist.py:75)
at robot.model.itemlist$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\itemlist.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py)
at robot.model.itemlist$py.visit$11(C:\jython2.7.0\Lib\site-packages\robot\model\itemlist.py:75)
at robot.model.itemlist$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\itemlist.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py)
at robot.utils.application$py._execute$10(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py:94)
at robot.utils.application$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py)
at robot.utils.application$py.execute_cli$5(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py:49)
at robot.utils.application$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py)
at runpy$py._run_code$9(C:\jython2.7.0\Lib\runpy.py:73)
at runpy$py.call_function(C:\jython2.7.0\Lib\runpy.py)
at runpy$py._run_module_as_main$14(C:\jython2.7.0\Lib\runpy.py:161)
at runpy$py.call_function(C:\jython2.7.0\Lib\runpy.py)
Caused by: java.lang.ClassNotFoundException: 
com.github.markusbernhardt.selenium2library.utils.WebDriverCache
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)
... 190 more

我在这个博客中使用的 Java 代码

注意:我还使用依赖 jar 文件“robotframework-selenium2library-java-1.4.0.8-jar-with-dependencies”进行了验证。我仍然面临同样的问题。

4

1 回答 1

1

“博客”/stackoverflow 帖子中的示例存在一些问题,关键是类的名称已更改,因为答案是写在 SO 上的。但是,当我编译 jar 文件并将 jar 文件添加到类路径部分时,red.xml没有遇到问题中提到的错误。由于提到的 SO 问题有两种方法,我都尝试了它们。

在我看来,您指定了目录而不是 .jar 文件robotframework-selenium2library-java-1.4.0.8

C:\jython2.7.0\bin\jython.exe
-J-Dpython.path=C:\jython2.7.0\Lib\site-packages
-J-cp .
;C:\Java\JarsKCC\Misc.jar
;C:\Java\JarsKCC\KCCUtils.jar
;C:\Java\JarsKCC\GetElementList.jar
;C:\jython2.7.0\selenium-server-standalone-3.3.1.jar
;C:\jython2.7.0\robotframework-selenium2library-java-1.4.0.8
-m robot.run
-P C:\jython2.7.0\Lib\site-packages\Selenium2Library
--listener C:\Users\CON_RT~1\AppData\ ... \TestRunnerAgent.py:56178:False
-s KCC_Automation.TestSuites.TestSeparateWebdriverInstance 
C:\Java\Workspace\KCC_Automation

所以我的建议是改变它,使类路径反映 jar 文件: ;C:\jython2.7.0\robotframework-selenium2library-java-1.4.0.8\some-jar-name.jar

于 2017-03-29T12:59:21.960 回答