I’m creating automated website and REST API tests using unittest in conjunction with webdriver and I want to achieve the following:
- Setup webdriver to use proxy server
- Using webdriver, open a web browser and navigate through pages performing various actions
- Intercept received responses in JSON format and validate them (JSON schema, keys and values, data types)
Is mitmproxy suitable for achieving my goal?
What I tried is to (based on the flowbasic example)
# start proxy server
cls.proxy_options = options.Options(cadir="~/.mitmproxy/")
cls.proxy_config = ProxyConfig(cls.proxy_options)
cls.proxy_server = ProxyServer(cls.proxy_config)
cls.proxy = proxy.Proxy(cls.proxy_options, cls.proxy_server)
# configure proxy for webdriver
cls.browser_profile = webdriver.FirefoxProfile()
However, this approach has failed as proxy.run() blocks the thread.
How to implement it properly? Maybe it’s possible to connect to already running instance of mitmproxy and intercept responses not using inline scripts?
Any help would be highly appreciated