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

问题描述 投票:1回答:1

问题

我正在docker-bridged网络中用mobbrowserproxy启动seleniumgrid。远程驱动程序代理设置配置正确,但我无法从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并使用chromedriver cli,则应该在终端中看到相同的错误。同样,此问题的目标是通过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 Mojave上。

建议

我认为此脚本最重要的部分是连接到中心和mob浏览器代理容器的变量

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

此脚本仅向您显示我如何设置您在chrome节点上的堆栈跟踪中已经在此处看到的首选项。

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)

参考

这些是我已经在网上找到的问题OneTwo-在此问题的底部,添加后已解决,如上所示。我已经尝试过了。

--disable-dev-shm-usage'

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

先前尝试

我不确定chromedriver或docker是否存在此问题。为了完成一些我已经尝试过的事情...1.我尝试登录chrome容器并使用chromedriver cli ...我也遇到相同的错误comment on issue 2我确实尝试使用包含chromedriver 74的图像作为下一个建议的注释next comment on issue 2

proxy docker-compose selenium-chromedriver selenium-grid
1个回答
0
投票

嗨@teaglebuilt您是否设法解决了这个问题?就我而言,问题是我试图在运行于AWS ECS容器上的jenkins代理上运行install chromedriver,以对其运行一些硒测试用例,并且可能会看到chromedriver失败并显示以下消息:

[SEVERE]: bind() failed: Cannot assign requested address (99).

当针对独立EC2代理运行且没有此错误时,测试可以完美运行。猜猜它是因为它是独立服务器而不是容器。

[像您一样尝试了以下为chrome提供的所有选项

options.addArguments("--disable-gpu"); 
options.addArguments("--headless"); 
options.addArguments("--priviliged");
options.addArguments("--headless"); 
options.addArguments("--whitelisted-ips="); 
options.addArguments("--disable-dev-shm-usage"); 
options.addArguments("--no-sandbox"); 
options.addArguments("--disable-extensions"); 
options.addArguments("--disable-background-networking"); 
options.addArguments("--enable-features=NetworkService,NetworkServiceInProcess"); 
options.setHeadless(true);

[已针对81和75版的chrome和chromedriver尝试过此操作,但没有运气。

我什至继续并更新了我的jenkins从属dockerfile,以包括chrome安装,但这也没有用。可能是我需要使用硒图像来解决此错误。

您能否分享您对此的发现/更新?

© www.soinside.com 2019 - 2024. All rights reserved.