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!
To Answer my own question based on the response from Sergey: I pushed a browsermob-proxy image to docker hub: https://hub.docker.com/r/spothero/browsermob-proxy/
created from this repository: https://github.com/sskorol/docker-browsermob-proxy
All credit goest to Sergey for the docker file.
My docker compose file:
On the jenkins job I have a shell step:
I use an environment variable to pass the hosts to my test code. Here is the code that initializes the webdriver with the proxy:
Hope this helps!