0

On an ubuntu system I am trying to use a 'browsernmob-proxy' with python-selenium tests. Following the documentation here I installed 'browsermob-proxy' and I tried the following python code:

from selenium import webdriver
from browsermobproxy import Server

server = Server("/home/adietz/Projects/Venv/nosetests/lib/python2.7/site-packages/browsermobproxy/server.py")
server.start()

but this immediately failed with the following error:

======================================================================
ERROR: test_example2.TestSuite.test_network
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/adietz/Projects/Venv/nosetests/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/adietz/Projects/Jenkins/bsp-usecase-tests/selenium/test_example2.py", line 41, in test_network
    server.start()
  File "/home/adietz/Projects/Venv/nosetests/local/lib/python2.7/site-packages/browsermobproxy/server.py", line 113, in start
    stderr=subprocess.STDOUT)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 13] Permission denied

Any idea how to fix this?

I also tried to use

server = Server("/home/adietz/Projects/Venv/nosetests/lib/python2.7/site-packages/browsermobproxy")

instead, but this failed with the following error:

======================================================================
ERROR: test_example2.TestSuite.test_network
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/adietz/Projects/Venv/nosetests/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/adietz/Projects/Jenkins/bsp-usecase-tests/selenium/test_example2.py", line 40, in test_network
    server = Server("/home/adietz/Projects/Venv/nosetests/lib/python2.7/site-packages/browsermobproxy")
  File "/home/adietz/Projects/Venv/nosetests/local/lib/python2.7/site-packages/browsermobproxy/server.py", line 81, in __init__
    "in path provided: %s" % path)
ProxyServerError: Browsermob-Proxy binary couldn't be found in path provided: /home/adietz/Projects/Venv/nosetests/lib/python2.7/site-packages/browsermobproxy

Addendum

  • I probably managed to get the browsermob-proxy to tun at port 8088 or 8089 (not exactly sure), but the example code still won't run ....
Alex
  • 34,021
  • 64
  • 178
  • 371

1 Answers1

-1

I guess, you are giving wrong path for the proxy server. Your code is pointing to the browsermob proxy python bindings instead of the server. Please follow the below steps.

  1. Download the browsermob proxy from the location https://github.com/lightbody/browsermob-proxy/releases and unzip the file to particular directory. I have extracted/unzipped to directory C:\\Projects\\BrowserMobProxy

  2. Install the browsermob proxy bindings if not already installed. pip install browsermob-proxy

  3. Then you can point the server path in the coding as follows. I am using windows. as given below.

    from browsermobproxy import Server
    server = Server("C:\\Projects\\BrowserMobProxy\\bin\\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.uk")
    proxy.har # returns a HAR JSON blob
    
    server.stop()
    driver.quit()
    

Please change the proxy path accordingly(where you have downloaded or extracted).

Murthi
  • 5,051
  • 1
  • 8
  • 15
  • I have done it as you described, but I got the error: "WebDriverException: Message: 'phantomjs' executable needs to be in PATH. " – Alex Jan 11 '18 at 09:27
  • The path I have used is: "/home/adietz/Projects/Jenkins/browsermob-proxy/browsermob-proxy-2.1.4/bin/browsermob-proxy" – Alex Jan 11 '18 at 09:29
  • are you using phantomjs browser? the error is not related to the browser mob proxy. may be you are missing the driver path for the phantomjs if it is used. – Murthi Jan 11 '18 at 09:34
  • What the heck is phantomjs? Its nowhere mentioned in the documentations I have found about using broswermob... – Alex Jan 11 '18 at 09:54