I am trying to use browsermob-proxy
to monitor all requests and responses for selenium tests. In my case, I am running the selenium
tests with the py.test
framework inside a docker
image on jenkins
. I am using the following versions:
- selenium==3.8.0
- pyvirtualdisplay==0.2.1
- pytest==3.4.0
- browsermob-proxy==0.8.0
also java openjdk-8-jdk
.
Inside the py.test
code I have the following line to create and start the server:
proxyserver = Server(
path="/root/tests/bsp_usecase_tests/bin/browsermob-proxy",
options={'port': 8090}
)
proxyserver.start()
driverproxy = proxyserver.create_proxy() # line 127
but in the last line I get the following error:
conftest.py:127: in basedriver
driverproxy = proxyserver.create_proxy()
/usr/local/lib/python2.7/dist-packages/browsermobproxy/server.py:40: in create_proxy
client = Client(self.url[7:], params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <browsermobproxy.client.Client object at 0x7f1a5f73f1d0>
url = 'localhost:8090', params = {}, options = {}
def __init__(self, url, params=None, options=None):
"""
Initialises a new Client object
:param url: This is where the BrowserMob Proxy lives
:param params: URL query (for example httpProxy and httpsProxy vars)
:param options: Dictionary that can contain the port of an existing
proxy to use (for example 'existing_proxy_port_to_use')
"""
params = params if params is not None else {}
options = options if options is not None else {}
self.host = "http://" + url
if params:
urlparams = "?" + unquote(urlencode(params))
else:
urlparams = ""
if 'existing_proxy_port_to_use' in options:
self.port = options['existing_proxy_port_to_use']
else:
resp = requests.post('%s/proxy' % self.host + urlparams)
content = resp.content.decode('utf-8')
try:
jcontent = json.loads(content)
except Exception as e:
raise Exception("Could not read Browsermob-Proxy json\n"
> "Another server running on this port?\n%s..." % content[:512])
E Exception: Could not read Browsermob-Proxy json
E Another server running on this port?
E <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
E <html><head>
E <meta type="copyright" content="Copyright (C) 1996-2016 The Squid Software Foundation and contributors">
E <meta http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">
E <title>ERROR: The requested URL could not be retrieved</title>
E <style type="text/css"><!--
E /*
E * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
E *
E * Squid software is distributed under GPLv2+ license and incl...
/usr/local/lib/python2.7/dist-packages/browsermobproxy/client.py:37: Exception
Maybe I forgot to copy important files into the docker image?
I have the following setup for the browsermob-proxy
(besides the pip install):
bsp_usecase_tests/bin:
browsermob-proxy
bsp_usecase_tests/lib:
browsermob-dist-2.1.4.jar
i.e. I have copied the file browsermob-proxy
into bin
and the file browsermob-dist-2.1.4.jar
into the lib
folder. Also, the server itself seem to be starting and running. But I get this weird error when I try to get the proxy information I can use for the selenium driver...
Any ideas what I have done wrong, or what is missing?