4

I am using the python client for browsermob to record traffic of my selenium tests. Selenium grid is in a docker container with images for chrome and firefox. I cant seem to configure the docker images properly to connect to the proxy and the grid. Here is the code that I use to create the proxy and the remote web driver:

server = browsermobproxy.Server('mylocalpathtobrowsermobbin')
server.start()
proxy = server.create_proxy()
proxy.new_har()
driver = webdriver.Remote(
                command_executor='http://127.0.0.1:4444/wd/hub',
                desired_capabilities={
                    'browserName': 'chrome',
                    'chromeOptions': {
                        'args': ["--proxy-server={}".format(proxy.proxy)]}
                    })

And this is my docker-compose file:

hub:
  image: selenium/hub
  ports:
     - "4444:4444"
chrome:
  image: selenium/node-chrome-debug
  volumes:
    - /dev/shm:/dev/shm
  links:
    - hub
  ports:
    - "5900:5900"

I am new to docker, I understand that I need to expose the port that the proxy uses to connect but I cannot get it working. Any help is appreciated, thanks!

4

2 回答 2

3

根据 Sergey 的回复回答我自己的问题:我将 browsermob-proxy 图像推送到 docker hub: https ://hub.docker.com/r/spothero/browsermob-proxy/

从这个存储库创建: https ://github.com/sskorol/docker-browsermob-proxy

Docker 文件的所有功劳都归功于 Sergey。

我的码头工人撰写文件:

中心:
  图片:硒/集线器
  端口:
     - “4444:4444”
火狐:
  图片:硒/节点火狐
  链接:
    - 中心
铬合金:
  图片:硒/节点铬调试
  卷:
    - /dev/shm:/dev/shm
  链接:
    - 中心
  端口:
    - “5900:5900”
浏览器mobproxy:
  图片:spothero/browsermob-proxy:1.0.0
  端口:
    - “9090-9191:9090-9191”
  暴露:
    - “9090-9191”
  链接:
    - 中心
    - 火狐
    - 铬合金

在詹金斯的工作中,我有一个 shell 步骤:

#!/bin/bash
docker-compose up -d --force-recreate
睡10s

PROXY_IP_ADDRESS="$(docker inspect --format {{.NetworkSettings.IPAddress}} browsermobproxy_1)"
导出 BROWSERMOB_CONTAINER_HOST=$PROXY_IP_ADDRESS

我使用环境变量将主机传递给我的测试代码。下面是使用代理初始化 webdriver 的代码:


    import browsermobproxy
    self.client = browsermobproxy.Client('localhost:9090')
    self.driver = webdriver.Remote(
        command_executor=settings.SELENIUM_GRID_HUB,
        desired_capabilities={
            'browserName': 'chrome',
            'chromeOptions': {
                'args': ["--proxy-server={}".format(
                    os.environ.get('BROWSERMOB_CONTAINER_HOST'), self.client.port)]
            }
        })

希望这可以帮助!

于 2017-09-07T17:28:26.673 回答
2

您还必须在容器中培养 BMP。然后将其与网格链接。查看本文以获取想法和关键实现/配置点。

于 2017-09-02T13:52:24.490 回答