我正在尝试使用selenium设置selenium和docker的浏览器测试。
我遇到的主要问题是运行测试时的可靠性。
有时我可以连接并且能够很好地运行测试,但很多时候我都不能。
看起来非常不一致,我启动容器并运行测试,第一次失败,再次运行,第二次运行并且工作正常。
一旦我重新启动selenium-hub并再次运行测试,它(大多数情况下)就可以了。
感谢您的帮助。
我得到的一个常见错误是:
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"
答案 0 :(得分:0)
您可以尝试将Chrome驱动程序更新为最新版本,它适用于我: https://sites.google.com/a/chromium.org/chromedriver/downloads
答案 1 :(得分:0)
我看到这个答案有很多观点,所以我想出了解决这个问题的方法。
因此,我在./conf/hosts_selenium:/etc/hosts
中的每个selenium节点添加了一个卷(docker-compose.yml
)。
...
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
- ./conf/hosts_selenium:/etc/hosts
links:
- selenium-hub
- web
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
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
shm_size: 2g
将主机文件添加到节点(./conf/hosts_selenium
):
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
这似乎解决了我的问题......很奇怪