如何在Selenium Chrome容器中设置代理?

时间:2018-05-03 07:21:20

标签: selenium docker proxy automated-tests selenium-chromedriver

我有一个docker-compose.yml文件,其中包含众所周知的环境变量,可以访问我们的公司代理:

---
version: '2.2'
# adapted from:
# https://github.com/SeleniumHQ/docker-selenium/wiki/Getting-Started-with-Docker-Compose
# docker-compose --force-recreate

services:
  chrome:
    privileged: True
    image: "selenium/standalone-chrome:3.11.0"
    ports:
      - "4444:4444"
    volumes:
      - /dev/shm:/dev/shm
    environment:
      - TZ="UT"
      - http_proxy=http://proxy.lan:8080
      - https_proxy=http://proxy.lan:8080
      - no_proxy=
      #- SE_OPTS=-Dhttp.proxyHost=proxy.lan -Dhttp.proxyPort=8080
    network_mode: host

当我在容器中运行wget时,代理将按预期使用。

    --2018-05-02 12:30:45--  http://google.com/
Resolving proxy.lan (proxy.lan)... 192.168.33.141
Connecting to proxy.lan (proxy.lan)|192.168.33.141|:8080... connected.
Proxy request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2018-05-02 12:30:45--  http://www.google.com/
Reusing existing connection to proxy.lan:8080.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘/dev/null’

/dev/null                                              [ <=>                                                                                                          ]  10.81K  --.-KB/s    in 0s

2018-05-02 12:30:46 (310 MB/s) - ‘/dev/null’ saved [11073]

但是,当我尝试使用SE_OPTS="-Dhttp.proxyHost=proxy.lan -Dhttp.proxyPort=8080"运行容器时,我看到了一个堆栈跟踪:

Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter '"-Dhttp.proxyHost=proxy.lan' but no main parameter was defined in your arg class.

有一个unmerged PR,但我担心在Se dev中可能感觉不到在企业环境中使用代理进行测试的紧迫性。也许有另一种解决方案。

0 个答案:

没有答案
相关问题