我正在尝试使用PhantomJS运行非常简单的Java自动化测试用例。我使用以下版本:
我的代码所需的功能和驱动程序启动如下:
DesiredCapabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"C:/Program Files/phantomjs-2.1.1-windows/bin/phantomjs.exe" //java web start / jnpl file...
// "/Controller/phantomjs.exe"
);
//SET enabled javascript for php script on WEB page to transform it to picture:
caps.setJavascriptEnabled(true);
String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
//CREATING WEB driver
WebDriver driver = new PhantomJSDriver(caps);
然而,我收到此错误:
线程“main”中的异常java.lang.NoClassDefFoundError: org / openqa / selenium / browserlaunchers / Proxies at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178) 在 org.openqa.selenium.phantomjs.PhantomJSDriver。(PhantomJSDriver.java:99) 在HD_PhantomJSTest1.main(HD_PhantomJSTest1.java:33)引起: 抛出java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies at java.net.URLClassLoader $ 1.run(URLClassLoader.java:372)at java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:360)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)at at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 3更多
答案 0 :(得分:0)
java.lang.NoClassDefFoundError
强> java.lang.NoClassDefFoundError
。
例如,如果我们从类中调用方法或访问类的任何静态成员,并且该类在运行时不可用,那么JVM将抛出 java.lang.NoClassDefFoundError
根据您的Test Bed
信息,我不确定是否包含 PhantomJSdriver.jar 1.1. version
。目前 PhantomJS
的实施并不需要任何额外的jar。相关的 Selenium JARs
可解决所需的依赖项。因此,您可以删除 PhantomJSdriver.jar 1.1. version
。
除此之外,我在代码中没有看到任何此类错误。但是,经过一些代码格式化后,我使用我的配置执行了代码,并且 SUCCESS
如下所示:
@Test
public void verifyFacebookTitle()
{
DesiredCapabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
caps.setJavascriptEnabled(true);
String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
WebDriver driver = new PhantomJSDriver(caps);
driver.get("https://www.facebook.com/");
System.out.println(driver.getTitle());
driver.quit();
}
我的控制台输出:
INFO: Detected dialect: OSS
Facebook – log in or sign up
[INFO - 2017-12-06T08:24:22.972Z] ShutdownReqHand - _handle - About to shutdown
PASSED: verifyFacebookTitle
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================