2

Running on a mac I am trying to use browsermob-proxy to monitor connections during python-selenium tests. I downloaded the java implementation 2.1.4 from here and pip installed the python wrapper ( browsermobproxy). The full example code is here (following examples found a lot):

from browsermobproxy import Server
server = Server("/Users/adietz/Projects/Invest/browsermob/browsermob-proxy-2.1.4/browsermob-dist/src/main/scripts/browsermob-proxy")
server.start()
proxy = server.create_proxy()

from selenium import webdriver
profile  = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)


proxy.new_har("google")
driver.get("http://www.google.co.in")
proxy.har

server.stop()
driver.quit()

But when running this code with python 3.6.2 gives the following error:

Traceback (most recent call last):
  File "tester1.py", line 3, in <module>
    server.start()
  File "/Users/adietz/Projects/Invest/browsermob/browsermob/lib/python3.6/site-packages/browsermobproxy/server.py", line 127, in start
    raise ProxyServerError("Can't connect to Browsermob-Proxy")

Is there a way to fix this error and be able to use browsermob-proxyon a mac?

Alex
  • 34,021
  • 64
  • 178
  • 371

2 Answers2

2

download this package https://bmp.lightbody.net/ put somewhere (maybe inside the bin folder of your pycharm project). the path of the proxy is like this

/home/andrea/PycharmProjects/selenium-performances/venv/bin/browsermob-proxy-2.1.4-bin/browsermob-proxy-2.1.4/bin/browsermob-proxy

but you can obtain the "Can't connect to Browsermob-Proxy" error if java is not installed,

try to run ./browsermob-proxy , the proxy should be able to run without exit for java not found error.

if you got the java error, install java (sudo apt install default-jdk on ubuntu) and retry.

Andrea Bisello
  • 722
  • 5
  • 16
1
 BrowserMobProxy proxyBrowser = new BrowserMobProxyServer();
    proxyBrowser.start(0);
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyBrowser);

    seleniumProxy.setHttpProxy("localhost:"+proxyBrowser.getPort());
    seleniumProxy.setSslProxy("localhost:"+proxyBrowser.getPort());

You need to add setHttpProxy and setSslProxy.

Worked for me