使用 SeleneseTestCase 运行 ANT 会导致 java.lang.NoClassDefFoundError
好的,所以我试图弄清楚为什么当我尝试运行扩展 SeleneseTestCase 的类时,junit 在 ANT 构建过程中失败。我可以手动运行测试,没有问题。只有当我尝试使用 ANT 构建和运行它时,我才会遇到这个问题。
我在 Mac 上使用 Eclipse 的最新版本:
selenium-java-client-driver-test.jar
selenium-java-client-driver.jar
selenium-server-standalone-2.0a7.jar
这些在 ANT Global Settings 下的全局设置中引用,并在我的 SeleneseTestCase 类中正确导入(我可以毫无问题地手动运行 testSuite.RegressionTest 以及测试类本身)。所以我在某个地方错过了 ANT 和 Selenium 之间的联系。
任何帮助或进一步的尝试都将受到极大的欢迎。
如果你曾经在圣地亚哥(我请喝酒!!!非常认真:))
这是我的控制台输出:
[junit] Testsuite: testSuite.RegressionTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test: Caused an ERROR
[junit] null
[junit] java.lang.reflect.InvocationTargetException
[junit] Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/selenium/SeleneseTestCase
[junit] at java.lang.ClassLoader.defineClass1(Native Method)
[junit] at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
[junit] at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
[junit] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
[junit] at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
[junit] at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit] at testSuite.RegressionTest.suite(Unknown Source)
[junit] Caused by: java.lang.ClassNotFoundException: com.thoughtworks.selenium.SeleneseTestCase
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit] Test testSuite.RegressionTest FAILED
更新:你可以看到 Selenium .jar 文件是已加载...
[javac] [类文件的搜索路径:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar,/System/Library/Java/JavaVirtualMachines/ 1.6.0.jdk/Contents/Classes/classes.jar,
...[删除不相关的加载类]...
/Applications/eclipse/plugins/junit-4.8。 2.jar,/Applications/eclipse/plugins/selenium-java-client-driver-tests.jar,/Applications/eclipse/plugins/selenium-java-client-driver.jar,/Applications/eclipse/plugins/selenium-server -standalone-2.0a7.jar]
...[删除不相关的加载类]...
Ok, so I'm trying to figure out why junit is failing during my ANT build when I try to run a class that extends a SeleneseTestCase. I can run the test manually without an issue. It's only when I try building and running it with ANT I get this problem.
I'm using Eclipse on the Mac with the latest version of:
selenium-java-client-driver-test.jar
selenium-java-client-driver.jar
selenium-server-standalone-2.0a7.jar
These are referenced in my global settings under the ANT Global Settings, and are imported properly in my SeleneseTestCase classes (I can run the testSuite.RegressionTest manually with no issues, as well as the test class itself). So somewhere I'm missing the linking between ANT and Selenium.
Any assistance, or further things to try would be greatly welcomed.
And if you're ever in San Diego (drinks are on me!!! dead serious :))
Here is my Console Output:
[junit] Testsuite: testSuite.RegressionTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test: Caused an ERROR
[junit] null
[junit] java.lang.reflect.InvocationTargetException
[junit] Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/selenium/SeleneseTestCase
[junit] at java.lang.ClassLoader.defineClass1(Native Method)
[junit] at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
[junit] at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
[junit] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
[junit] at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
[junit] at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit] at testSuite.RegressionTest.suite(Unknown Source)
[junit] Caused by: java.lang.ClassNotFoundException: com.thoughtworks.selenium.SeleneseTestCase
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit] Test testSuite.RegressionTest FAILED
UPDATE: You can see that the Selenium .jar files are loaded...
[javac] [search path for class files: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar,
...[REMOVED IRRELEVANT LOADED CLASSES]...
/Applications/eclipse/plugins/junit-4.8.2.jar,/Applications/eclipse/plugins/selenium-java-client-driver-tests.jar,/Applications/eclipse/plugins/selenium-java-client-driver.jar,/Applications/eclipse/plugins/selenium-server-standalone-2.0a7.jar]
...[REMOVED IRRELEVANT LOADED CLASSES]...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来不像是硒,而是让你头疼的蚂蚁。你用的是什么版本的蚂蚁?
这听起来绝对像是 ant 可能产生的类路径问题。我浪费了很多时间试图弄清楚为什么我的构建不起作用,结果却发现当我的任务运行时还有其他一些类路径变量被加载。当我明确调用新版本时,我什至不幸地加载了旧版本的 ant(隐藏在 Weblogic 深处)。那是我一生中浪费的 4 个小时...
我的建议是在你的 ant 脚本中创建一个类路径变量,明确命名你想要使用的 jar,并使用“-v”(用于详细)运行你的 ant 任务来查看什么确实是在运行时加载的。
俗话说“如果它闻起来像鸭子,走路像鸭子,拉屎像鸭子,那么你可能就是一只鸭子”
It doesn't look like it's selenium, but rather ant that is giving you a headache. What version of ant are you using?
This definitely sounds like a classpath issue that could be generated from ant. I have spent many a wasted hour trying to figure out why my builds weren't working only to find out that there was some other classpath variable getting loaded when my task ran. I've even had the misfortune of loading an older version of ant (hidden deep within Weblogic) when I was explicitly calling a newer version. That was 4 wasted hours of my life...
My suggestion is to create a classpath variable in your ant script that explicitly names the jars you want to use, and run your ant task with '-v' (for verbose) to see what is really loaded at runtime.
The old saying goes 'if it smells like a duck, walks like a duck, and poops like a duck, then you've probably got a duck'