-
Hi there, I have a dodgy Is there a (SeleniumBase is great btw, thanks!) The import browsermobproxy
import selenium.webdriver as driver
import time
website_homepage_url = "http://www.python.org"
server = browsermobproxy.Server("C:\Users\johnsmith\Computer_Code\\browsermob-proxy-2.1.0-beta-1\\bin\\browsermob-proxy")
server.start()
proxy = server.create_proxy()
profile = driver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
browser = driver.Firefox(firefox_profile=profile)
proxy.new_har("Python.org")
proxy.rewrite_url(website_homepage_url, 'http://localhost:8000/Fake_Search_Results_Page.html')
browser.get(website_homepage_url)
time.sleep(10)
proxy.har # returns a HAR JSON blob
server.stop()
browser.quit() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @rdmolony, SeleniumBase allows you to set a proxy server when running tests, which you can use together with the browsermobproxy. There are two ways to set the proxy. |
Beta Was this translation helpful? Give feedback.
Hello @rdmolony, SeleniumBase allows you to set a proxy server when running tests, which you can use together with the browsermobproxy. There are two ways to set the proxy.
1: From the command-line with pytest:
--proxy="server:port"
2: By spinning up a new driver from within a test:
driver2 = self.get_new_driver(proxy="server:port")
If authentication is required, you can expand that format to
user:pass@server:port
.If using option 2, all
self.*
methods will automatically start using the new driver that you have spun up. Assuming that you have correctly set up your proxy server, the web browser will use that while tests are running.