How to use browsermob with python-selenium?

前端 未结 4 523
旧巷少年郎
旧巷少年郎 2020-12-09 11:42

I want to use browsermob to monitor the network connections when doing a GUI test with selenium. I have found some information and documentation here and here and here, but

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 12:13

    You need to configure the driver to use BMP as a proxy so it can record the network activity. Here is an example....

    from browsermobproxy import Server
    from selenium import webdriver
    
    server = Server('/path/to/bmp/bin/browsermob-proxy') #Local path to BMP
    server.start()
    proxy = server.create_proxy() #Proxy is used to generate a HAR file containing the connection URLS that the MP3s are loaded from.
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy)) #Configure chrome options
    driver = webdriver.Chrome(chrome_options=chrome_options)
    proxy.new_har('filename') 
    

    Then all the activity will be recorded to that file.

    In my case, the path for the binary file was C:\Python27\Lib\site-packages\browsermobproxy\browsermob-proxy-2.1.0-beta-3\bin\browsermob-proxy on Windows with Python 2.7

提交回复
热议问题