我正在尝试在 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'