2017-08-09 103 views
0

我裝了一個應用程序,它是自動Selenium測試的測試驅動程序。 Selenium服務器(也稱爲Selenium Hub)在localhost:4444下運行在另一個容器以及Firefox節點中。 但我的應用程序是無法達到的: Docker容器無法訪問本地主機端口4444.爲什麼?

Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 
 
System info: host: '10d3b5fd1010', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_11   1' 
 
Driver info: driver.version: RemoteWebDriver 
 
     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665) 
 
     at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249) 
 
     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131) 
 
     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158) 
 
     at de.services.impl.TestSetupFactory.getWebDriver(TestSetupFactory.java:408) 
 
     at de.services.impl.TestSetupFactory.getSeleniumService(TestSetupFactory.java:279) 
 
     at de.services.impl.AutomationServiceImpl.executeTests(AutomationServiceImpl.java:220) 
 
     at de.start.Start.main(Start.java:25) 
 
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:4444 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: C   onnection refused (Connection refused) 
 
     at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158) 
 
     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)

我開始通過搬運工,撰寫這些容器:

version: '2' 
 
services: 
 
    hub: 
 
    image: selgrid:1.1 
 
    ports: 
 
     - "4444:4444" 
 

 
    firefox: 
 
    #pull latest from docker hub 
 
    image: selenium/node-firefox 
 
    volumes: 
 
     - /dev/urandom:/dev/random 
 
    depends_on: 
 
     - hub 
 
    environment: 
 
     - HUB_PORT_4444_TCP_ADDR=hub 
 
     - HUB_PORT_4444_TCP_PORT=4444 
 
    testautomation: 
 
    #run testautomation app 
 
    image: volumetest 
 
    links: 
 
     - "hub" 
 
    ports: 
 
     - "9005:9005"

我想有一個錯誤我的碼頭 - 撰寫,但我無法弄清楚。請幫忙! btw:我在Windows 7上運行,並將Docker與Vagrant VM結合使用。在我的Vagrantfile中,我將端口4444和9005映射到主機系統。如果我打開本地瀏覽器並訪問本地主機:4444,我可以看到硒網格控制檯。爲什麼它不能從我的應用程序容器中工作?

回答

1

在您的應用程序容器中localhost表示當前容器。所以你需要使用服務的名稱。而你的情況是hub

所以連接到hub:4444

+0

首先我的容器甚至不能達到中心:4444,但是當我從一個碼頭工人撰寫文件開始的一切,鏈接的樞紐,以我的應用程序容器,一切都只是正常工作。謝謝 – Timo

0

我面臨着同樣的問題,轉移到泊塢窗,撰寫版本2之後。 此日誌,我得到

Connect to localhost:4444 [localhost/127.0.0.1] failed: Connection refused 
 

 
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.

下面是搬運工,撰寫YML文件的樣子:

version: '2' 
 
services: 
 
    seleniumhub: 
 
    image: selenium/hub 
 
    ports: 
 
     - 4444:4444 
 
    firefoxnode: 
 
    image: selenium/node-firefox-debug 
 
    ports: 
 
     - 5900 
 
    environment: 
 
     - HUB_PORT_4444_TCP_ADDR=seleniumhub 
 
     - HUB_PORT_4444_TCP_PORT=4444 
 
    webdrivertests: 
 
    image: vodqa/gridtests 
 
    volumes: 
 
     - ./temp:/usr/src/app/target 
 
    environment: 
 
     - HUB_PORT_4444_TCP_ADDR=seleniumhub 
 
     - HUB_PORT_4444_TCP_PORT=4444 
 
    command: bash -c "cd /usr/src/app && mvn test"

在我的測試中,我嘗試訪問集線器使用:

new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),desiredCapabilitiesff );

+0

我得到了它的工作。謝謝@Tarun Lalwani。剛剛將'http:// localhost:4444/wd/hub'更改爲'http:// seleniumhub:4444/wd/hub' –

相關問題