无法将seleniumgrid中的dockerchrome节点绑定到代理容器



问题

我正在docker桥接网络中使用mobbrowserproxy启动硒网格。远程驱动程序代理设置配置正确,但我无法从chrome驱动程序连接到代理服务器。我看了所有的问题,但找不到解决办法。

以下是显示驱动程序所需功能/选项的错误。

Stacktrace

selenium-hub    | 15:40:24.222 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=ef95a1c8-8c30-472b-9e5e-323b8a8c9045, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=1, platformName=LINUX, version=74.0.3729.169, applicationName=, platform=LINUX}
chrome_1        | 15:40:24.243 INFO [ActiveSessionFactory.apply] - Capabilities are: {
chrome_1        |   "browserName": "chrome",
chrome_1        |   "goog:chromeOptions": {
chrome_1        |     "args": [
chrome_1        |       "--disable-gpu",
chrome_1        |       "--headless",
chrome_1        |       "--no-sandbox",
chrome_1        |       "--whitelisted-ips",
chrome_1        |       "--disable-dev-shm-usage",
chrome_1        |       "--allow-insecure-localhost",
chrome_1        |       "--disable-web-security",
chrome_1        |       "--ignore-certificate-errors",
chrome_1        |       "--allow-running-insecure-content"
chrome_1        |     ],
chrome_1        |     "extensions": [
chrome_1        |     ]
chrome_1        |   },
chrome_1        |   "proxy": {
chrome_1        |     "httpProxy": "0.0.0.0:9099",
chrome_1        |     "proxyType": "manual",
chrome_1        |     "sslProxy": "0.0.0.0:9099"
chrome_1        |   },
chrome_1        |   "version": ""
chrome_1        | }
chrome_1        | 15:40:24.243 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
chrome_1        | Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 28080
chrome_1        | Only local connections are allowed.
chrome_1        | Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
chrome_1        | [1589038824.252][SEVERE]: bind() failed: Cannot assign requested address (99)
chrome_1        | 15:40:24.418 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
chrome_1        | 15:40:24.444 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 4c42082804845cf9571e6a843a63feca (org.openqa.selenium.chrome.ChromeDriverService)
chrome_1        | 15:40:34.798 INFO [ActiveSessions$1.onStop] - Removing session 4c42082804845cf9571e6a843a63feca (org.openqa.selenium.chrome.ChromeDriverService)

我相信这个堆叠竞赛的关键点就在这里

chrome_1        | Only local connections are allowed.
chrome_1        | Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
chrome_1        | [1589038824.252][SEVERE]: bind() failed: Cannot assign requested address (99)

复制

重现此错误。如果你简单地启动容器并登录chromenode并使用chromedrivercli,你应该会在终端中看到同样的错误。同样,这个问题的目标是通过chromedriver代理设置连接代理容器。

version: "3"
services:
selenium-hub:
image: selenium/hub:3.141.59-20200409
container_name: selenium-hub
ports:
- "4444:4444"
networks: 
- caowebtests
chrome:
image: selenium/node-chrome:3.141.59-oxygen
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
networks: 
- caowebtests
expose: 
- 9515
firefox:
image: selenium/node-firefox:3.141.59-20200409
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
networks: 
- caowebtests
opera:
image: selenium/node-opera:3.141.59-20200409
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
networks: 
- caowebtests
proxy:
image: spothero/browsermob-proxy:1.0.0
depends_on:
- selenium-hub
networks: 
- caowebtests
ports:
- "9090:9090"
links:
- selenium-hub
- firefox
- chrome
- opera
robottests:
container_name: robottests
command: /bin/sleep infinity
depends_on:
- selenium-hub
build: .
volumes:
- ./reports:/cao_ui_tests/reports
networks: 
- caowebtests

networks:
caowebtests:
driver: bridge

正如您在上面的跟踪中所看到的。所需的功能和选项都在那里。我想弄清楚的是,chrome驱动程序在上面的代理设置中出现这个错误的原因。

在登录页面上查找第一个元素时,我的测试失败了。我不确定你是否需要测试脚本和执行测试脚本的能力来尝试重现这一点,或者这是否是可以指出的。如果需要,我可以将此回购添加到github。

下面的测试脚本

*** Settings ***
Library    BrowserMobProxy
Library    SeleniumLibrary
Library    RequestsLibrary
Library    Collections
Resource   resources${/}base.robot
Resource   resources${/}common.robot
Resource   resources${/}auth.robot
Suite Setup  Setup Test Suite
Test Teardown  Close All Browsers
Suite Teardown  Test Suite Teardown

*** Variables ***
${BMP_HOST}  0.0.0.0
${BMP_PORT}  9090
${SELENIUM}  http://0.0.0.0:4444/wd/hub
${SHOT_NUM}  0
@{TIMINGS}

*** Test Cases ***
Login User
Wait Until Page Loads
Wait Until Page Contains Element  ${UI['login']}  timeout=10
Submit Credentials  %{TEST_USER}  %{TEST_PASS}



*** Keywords ***
Setup Test Suite
Load UI Repository  ${REPO_PATH}
Connect To Remote Server  ${BMP_HOST}  ${BMP_PORT}
Set Selenium Implicit Wait  0.2 seconds
Set Selenium Timeout  30 seconds
${prefs}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
&{caps}=  Set Capabilities
Call Method  ${prefs}  add_argument  --disable-gpu 
Call Method  ${prefs}  add_argument  --headless 
Call Method  ${prefs}  add_argument  --no-sandbox
Call Method  ${prefs}  add_argument  --whitelisted-ips
Call Method  ${prefs}  add_argument  --disable-dev-shm-usage
Call Method  ${prefs}  add_argument  --allow-insecure-localhost
Call Method  ${prefs}  add_argument  --disable-web-security
Call Method  ${prefs}  add_argument  --ignore-certificate-errors
Call Method  ${prefs}  add_argument  --allow-running-insecure-content
Create Webdriver  Remote  command_executor=${SELENIUM}  desired_capabilities=${caps}  
options=${prefs}
New Har  LoginPage
Go To  https://cardatonce.eftsource.com

Test Suite Teardown
Get Har  file.har
Close Proxy

Set Capabilities
[Documentation]  Set the options for the selenium Driver
${port}=  Create Proxy
&{proxy}=  Create Dictionary
...  proxyType  MANUAL
...  sslProxy  ${BMP_HOST}:${port}
...  httpProxy  ${BMP_HOST}:${port}
&{caps}=  Create Dictionary  browserName=chrome  platform=ANY  proxy=&{proxy}
Log  Selenium capabilities: ${caps}
[return]  ${caps}
Create Proxy
[Documentation]  Get a BMP port for our test
Create Session  bmp  http://${BMP_HOST}:${BMP_PORT}
${resp}=  Get Request  bmp  /proxy
Should Be Equal As Strings  ${resp.status_code}  200
Log  BMP Sessions: ${resp.text} [${resp.status_code}]
&{headers}=  Create Dictionary  Content-Type=application/x-www-form-urlencoded
&{data}=  Create Dictionary  trustAllServers=True
${resp}=  Post Request  bmp  /proxy  data=${data}  headers=${headers}
Should Be Equal As Strings  ${resp.status_code}  200
Log  ${resp.text} [${resp.status_code}]
${port}=  Get From Dictionary  ${resp.json()}  port
Log  New BMP port: ${port} [${resp.status_code}]
Set Global Variable  ${port}
[return]  ${port}

Close Proxy
${resp}=  Delete Request  bmp  /proxy/${port}
Should Be Equal As Strings  ${resp.status_code}  200
Log  Closed proxy at ${port} [${resp.status_code}]

New Har
[Documentation]  Name and initialize a Har
[arguments]  ${pagename}
&{data}=  Create Dictionary  initialPageRef=${pagename}
${resp}=  Put Request  bmp  /proxy/${port}/har  params=${data}
#Should Be Equal As Strings  ${resp.status_code}  204
Log  New Har (${pagename}) [${resp.status_code}]

环境

这是一辆MacOs莫哈韦。

建议

我认为这个脚本最重要的部分是连接到集线器和mob浏览器代理容器的变量

${BMP_HOST}  0.0.0.0
${BMP_PORT}  9090
${SELENIUM}  http://0.0.0.0:4444/wd/hub

这个脚本只是向您展示了我是如何设置您在chrome节点上的stacktrace中已经看到的首选项的。

chrome_1        | Only local connections are allowed.
chrome_1        | Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
chrome_1        | [1589038824.252][SEVERE]: bind() failed: Cannot assign requested address (99)

参考文献

这些是我在网上已经发现的问题一二——在这个问题的底部,它通过添加得到了解决,正如你在上面看到的那样。我已经试过了。

--disable-dev-shm-usage'

三这个家伙通过在docker配置中添加ipv6解决了这个问题。但我在docker compose中使用了一个桥接网络,所以我不明白为什么这个选项会很重要。。。。

以前的尝试

我不确定这是chromedriver还是docker的问题。为了完成我已经尝试过的一些事情。。。1.我尝试登录chrome容器并使用chromedriver cli。。。我也犯了同样的错误对问题2的评论我确实尝试使用了包含chromedriver 74的图像作为下一条评论关于问题2 的下一条评论

消除

chrome_1        | Only local connections are allowed.
chrome_1        | [1589038824.252][SEVERE]: bind() failed: Cannot assign requested address (99)

您需要通过设置docker chrome节点镜像的envJAVA_OPTS


chrome:
image: selenium/node-chrome:3.141.59-oxygen
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- JAVA_OPTS=-Dwebdriver.chrome.whitelistedIps=
networks: 
- caowebtests
expose: 
- 9515

相关内容

  • 没有找到相关文章

最新更新