2017-02-09 49 views
2

試圖做一些培訓Java Selenium測試,我有麻煩的網絡驅動程序破壞... 我的代碼是非常非常簡單..然而,它贏了沒有工作。 我正在使用macOS Seirra Verion 10.12.3。org.openqa.selenium.WebDriverException:chrome無法訪問

我的代碼是:

import org.junit.Test; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.junit.Assert; 

/** 
* Created by wizzz-mac on 08/02/2017. 
*/ 
public class FirstTest { 

    @Test 
    public void startWebDriver(){ 
     System.setProperty("webdriver.chrome.driver", "/Users/wizzz-mac/Downloads/chromedriver"); 
     WebDriver wd = new ChromeDriver(); 
     System.out.println(wd.getTitle()); 
     wd.close(); 
     wd.quit(); 
    } 
} 

,這是pom.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>myFirstSeleniumProject</groupId> 
    <artifactId>myFirstSeleniumProject</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <dependencies> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.53.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-chrome-driver</artifactId> 
      <version>2.9.0</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 

    </dependencies> 
</project> 

,這是錯誤我得到

/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7536 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA CE.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/tools.jar:/Users/wizzz-mac/IdeaProjects/myFirstSeleniumProject/target/test-classes:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-java/2.53.1/selenium-java-2.53.1.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-edge-driver/2.53.1/selenium-edge-driver-2.53.1.jar:/Users/wizzz-mac/.m2/repository/commons-io/commons-io/2.4/commons-io-2.4.jar:/Users/wizzz-mac/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/htmlunit-driver/2.21/htmlunit-driver-2.21.jar:/Users/wizzz-mac/.m2/repository/net/sourceforge/htmlunit/htmlunit/2.21/htmlunit-2.21.jar:/Users/wizzz-mac/.m2/repository/xalan/xalan/2.7.2/xalan-2.7.2.jar:/Users/wizzz-mac/.m2/repository/xalan/serializer/2.7.2/serializer-2.7.2.jar:/Users/wizzz-mac/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar:/Users/wizzz-mac/.m2/repository/org/apache/httpcomponents/httpmime/4.5.2/httpmime-4.5.2.jar:/Users/wizzz-mac/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/Users/wizzz-mac/.m2/repository/net/sourceforge/htmlunit/htmlunit-core-js/2.17/htmlunit-core-js-2.17.jar:/Users/wizzz-mac/.m2/repository/net/sourceforge/htmlunit/neko-htmlunit/2.21/neko-htmlunit-2.21.jar:/Users/wizzz-mac/.m2/repository/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar:/Users/wizzz-mac/.m2/repository/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar:/Users/wizzz-mac/.m2/repository/net/sourceforge/cssparser/cssparser/0.9.18/cssparser-0.9.18.jar:/Users/wizzz-mac/.m2/repository/org/w3c/css/sac/1.3/sac-1.3.jar:/Users/wizzz-mac/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/wizzz-mac/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.2.15.v20160210/websocket-client-9.2.15.v20160210.jar:/Users/wizzz-mac/.m2/repository/org/eclipse/jetty/jetty-util/9.2.15.v20160210/jetty-util-9.2.15.v20160210.jar:/Users/wizzz-mac/.m2/repository/org/eclipse/jetty/jetty-io/9.2.15.v20160210/jetty-io-9.2.15.v20160210.jar:/Users/wizzz-mac/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.2.15.v20160210/websocket-common-9.2.15.v20160210.jar:/Users/wizzz-mac/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.2.15.v20160210/websocket-api-9.2.15.v20160210.jar:/Users/wizzz-mac/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-firefox-driver/2.53.1/selenium-firefox-driver-2.53.1.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-ie-driver/2.53.1/selenium-ie-driver-2.53.1.jar:/Users/wizzz-mac/.m2/repository/net/java/dev/jna/jna/4.1.0/jna-4.1.0.jar:/Users/wizzz-mac/.m2/repository/net/java/dev/jna/jna-platform/4.1.0/jna-platform-4.1.0.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-safari-driver/2.53.1/selenium-safari-driver-2.53.1.jar:/Users/wizzz-mac/.m2/repository/io/netty/netty/3.5.7.Final/netty-3.5.7.Final.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-support/2.53.1/selenium-support-2.53.1.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-leg-rc/2.53.1/selenium-leg-rc-2.53.1.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-chrome-driver/2.9.0/selenium-chrome-driver-2.9.0.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-remote-driver/2.9.0/selenium-remote-driver-2.9.0.jar:/Users/wizzz-mac/.m2/repository/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar:/Users/wizzz-mac/.m2/repository/org/json/json/20080701/json-20080701.jar:/Users/wizzz-mac/.m2/repository/org/seleniumhq/selenium/selenium-api/2.9.0/selenium-api-2.9.0.jar:/Users/wizzz-mac/.m2/repository/com/google/guava/guava/r09/guava-r09.jar:/Users/wizzz-mac/.m2/repository/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2.jar:/Users/wizzz-mac/.m2/repository/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2.jar:/Users/wizzz-mac/.m2/repository/junit/junit/4.12/junit-4.12.jar:/Users/wizzz-mac/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 FirstTest,startWebDriver 
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 15818 
Only local connections are allowed. 
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 9515 
Only local connections are allowed. 

org.openqa.selenium.WebDriverException: chrome not reachable 
    (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.3 x86_64) (WARNING: The server did not provide any stacktrace information); duration or timeout: 60.36 seconds 
Build info: version: '2.9.0', revision: '14289', time: '2011-10-20 23:22:17' 
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.3', java.version: '1.8.0_121' 
Driver info: driver.version: ChromeDriver 

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:147) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:417) 
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:115) 
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:76) 
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:120) 
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:87) 
    at FirstTest.startWebDriver(FirstTest.java:14) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 


Process finished with exit code 255 

我認爲這個問題是「在端口15818上啓動ChromeDriver 2.27.440174(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9)只有l ocal連接是允許的。 端口開始ChromeDriver 2.27.440174(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9)9515 只有本地連接被允許。」部分

非常感謝你的幫助

+0

你有最新版本的chromedriver嗎?如果不是,請嘗試更新它。 – Thibstars

+0

如果你能看到,iv'e將chrome驅動程序的屬性設置爲我從互聯網上下載的最新的chromedriver。所以它似乎不是問題 –

+0

並且您的瀏覽器是否正確打開?如果沒有,這可能是這一個重複的問題:http://stackoverflow.com/questions/25080500/when-running-webdriver-with-chrome-browser-getting-message-only-local-connect – Thibstars

回答

2

其他的答案沒有解決問題 - 我的解決方法很簡單:我剛剛重新安裝Chrome瀏覽器(不chromedriver)和 - 它的工作原理

+0

當然。此外:考慮清理不再需要的評論。 – GhostCat

0

如果你泊塢窗內運行這一點,你可能需要通過泊塢窗運行命令

--privileged 
+0

我沒有使用docker,在mac os上運行在Intellij上的簡單的硒測試,沒有別的...... –