Reputation: 265
I'm trying to check on the network traffic on a site using Browsermob Proxy. By running the following: I've found that the Proxy server is refusing connections:
"the proxy server is refusing connections" "firefox is configured to use a proxy that is refusing connections."
I have yet to find an example in python setting up a proxy with remote webdriver.
server = Server("location/browsermob-proxy-2.0-beta-9/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("impression")
driver.get("https://www.google.com/")
server.stop()
driver.quit()
#success
from browsermobproxy import Server
server = Server("location/browsermob-proxy-2.0-beta-9/bin/browsermob-proxy")
server.start()
our_proxy = server.create_proxy()
from selenium import webdriver
our_browser = browser.upper()
desired_capabilities = webdriver.DesiredCapabilities.FIREFOX # Default
desired_capabilities["version"] = configs[browser]["browser-version"]
desired_capabilities["platform"] = configs[browser]["os"]
desired_capabilities["idle-timeout"] = "25"
desired_capabilities["max-duration"] = "300"
desired_capabilities["command-timeout"] = "30"
desired_capabilities["name"] = test_name
desired_capabilities["browserName"] = browser
desired_capabilities['loggingPrefs'] = {"browser":"ALL"}
this_proxy = Proxy({
"httpProxy":our_proxy.selenium_proxy().httpProxy,
"sslProxy":our_proxy.selenium_proxy().sslProxy,
"proxyType":"MANUAL",
"autodetect":False
})
this_proxy.add_to_capabilities(desired_capabilities)
driver = webdriver.Remote(
desired_capabilities = desired_capabilities
)
proxy.new_har("impression")
driver.get("https://www.google.com/")
#fails
#urllib2.URLError: <urlopen error [Errno 61] Connection refused>
server.stop()
driver.quit()
desired_capabilites for remote and firefoxprofile respectively:
{'name': 'abdc', 'javascriptEnabled': True, 'idle-timeout': '25', 'command-timeout': '30', 'max-duration': '300', 'platform': 'Windows 7', 'browserName': 'firefox', 'version': '28', 'proxy': {'proxyType': 'MANUAL', 'sslProxy': 'localhost:9117', 'httpProxy': 'localhost:9117'}, 'loggingPrefs': {'browser': 'ALL'}}
{u'rotatable': False, u'takesScreenshot': True, u'acceptSslCerts': True, u'cssSelectorsEnabled': True, u'javascriptEnabled': True, u'databaseEnabled': True, u'locationContextEnabled': True, u'platform': u'Darwin', u'browserName': u'firefox', u'version': u'29.0.1', u'nativeEvents': False, u'applicationCacheEnabled': True, u'webStorageEnabled': True, u'browserConnectionEnabled': True, u'handlesAlerts': True}
I've seen this ticket which says the issue is resolved; but it doesn't seem so.
https://code.google.com/p/selenium/issues/detail?id=2051
Upvotes: 4
Views: 2974
Reputation:
I was facing the same error earlier. This is generally due to a process running on the same port which is not letting browsermob proxy to start. Generally Apache Tomcat is using the same server.
Either change the port for Browsermob.
server = Server(browsermob_location,options={'port':port_browsermob})
Here port_browsermob is the port which you can specify.
Upvotes: 0