我正在嘗試使用硒和docker與behat進行瀏覽器測試。Docker和Selenium無法連接到渲染器
我在運行測試時遇到的主要問題是可靠性問題。
有時我可以連接並能夠正常運行測試,但很多時候我不能。
這似乎很不一致,我啓動容器並運行測試,第一次失敗,再次運行,第二次運行並正常工作。
一旦我重新啓動硒轂並再次運行測試它很好(主要)。
感謝您的幫助。
一個常見的錯誤我得到的是:
Could not open connection: session not created exception
from disconnected: unable to connect to renderer
(Session info: chrome=61.0.3163.91)
(Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-96-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 411 milliseconds
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
System info: host: 'e0218fe24a14', ip: '172.18.0.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version: '1.8.0_131'
Driver info: driver.version: unknown (Behat\Mink\Exception\DriverException)
泊塢窗,compose.yml
version: '2'
services:
db:
build:
context: .
dockerfile: DockerfileDb
container_name: db
ports:
- "3396:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
web:
build:
context: .
dockerfile: DockerfileWeb
depends_on:
- db
container_name: web
ports:
- "8080:80"
links:
- db
- selenium-hub
environment:
- LOCALHOST_DOCKER=db
- MYSQL_USER=root
- MYSQL_PASSWORD=password
volumes:
- ./conf/rsyslog.conf:/etc/rsyslog.d/rsyslog-custom.conf
- ./:/var/www
- ./sites-enabled:/etc/apache2/sites-enabled
- ./conf/hosts:/etc/hosts
selenium-hub:
container_name: selenium_hub
image: selenium/hub
ports:
- "4444:4444"
chrome:
container_name: selenium_node_chrome
image: selenium/node-chrome
volumes:
- /dev/shm:/dev/shm # Mitigates the Chromium issue described at https://code.google.com/p/chromium/issues/detail?id=519952
links:
- selenium-hub
- web
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
volumes:
- ./conf/hosts_selenium:/etc/hosts
depends_on:
- selenium-hub
shm_size: 1g
firefox:
container_name: selenium_node_firefox
image: selenium/node-firefox
links:
- selenium-hub
- web
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
volumes:
- ./conf/hosts_selenium:/etc/hosts
depends_on:
- selenium-hub
behat.yml
default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
Behat\MinkExtension:
base_url: http://**********:8080/
default_session: laravel
laravel: ~
selenium2:
wd_host: http://selenium_node_chrome:5555/wd/hub
capabilities: {'platform': 'LINUX', 'browser': 'chrome'}
browser_name: chrome
login.feature
@mink:selenium2
Feature: login
Users should be able to login
Scenario: Login Successfully # features/Login.feature:5
When I wait 1 seconds # FeatureContext::iWaitSeconds()
Could not open connection: session not created exception
from disconnected: unable to connect to renderer
(Session info: chrome=61.0.3163.91)
(Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-96-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 411 milliseconds
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
System info: host: 'e0218fe24a14', ip: '172.18.0.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version: '1.8.0_131'
Driver info: driver.version: unknown (Behat\Mink\Exception\DriverException)
Given I am on "/" # FeatureContext::visit()
Then print current URL # FeatureContext::printCurrentUrl()
Then take screenshot "test1.png" # FeatureContext::takeScreenshot()
Then I should not see "Whoops" # FeatureContext::assertPageNotContainsText()
And I should not see "ERR_NAME_NOT_RESOLVED" # FeatureContext::assertPageNotContainsText()
Then take screenshot "login_test.png"
看到Chrome容器的日誌,看看是否你發現錯誤? –