我正在尝试在OS X上使用chrome运行selenium测试。它可以与firefox一起使用,但Chrome驱动程序似乎与浏览器无法通信。
这是我的代码:
import junit.framework.TestCase;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DriverTest extends TestCase {
public void testFirefox(){
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.close();
}
public void testChrome(){
ChromeDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.close();
}
}
当我运行它时,firefox启动正常,但对于chrome我得到这个错误:
Started ChromeDriver
port=45421
version=23.0.1240.0
log=/Users/user/projects/client/hg/chromedriver.log
objc[25753]: Object 0x6e078170 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e078360 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e078410 of class NSConcreteData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e078470 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e0782c0 of class NSBundle autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.4', java.version: '1.6.0_35'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:493)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:182)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:165)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
at DriverTest.testChrome(DriverTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
Caused by: org.openqa.selenium.WebDriverException: Unable to convert: {desiredCapabilities=Capabilities [{platform=ANY, browserName=chrome, chromeOptions=org.openqa.selenium.chrome.ChromeOptions@448be1c9, chrome.switches=[], version=}]}
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01'
答案 0 :(得分:0)
您需要指定指向Chromedriver位置的系统属性,例如:
System.setProperty("webdriver.chrome.driver", "applications/chrome/chromedriver");
第二个参数应设置为保存chromedriver的路径。
答案 1 :(得分:0)
尝试为ChromeDriver设置DesiredCapabilities.chrome()。
ChromeDriver driver = new ChromeDriver(DesiredCapabilities.chrome());
这应该有用。