Httpwatch 一款强大的网页数据分析工具。它可以捕捉http/https数据,查看底层的数据,包括headers、cookies、cache等。同时,记录发送请求、接收请的时间。Anyway,a good tool for you。
或许,你有一个需求,要在selenium进行页面功能测试的时候,你需要获取一些信息,如提交请求数据、接收请求数据、页面加载的时间等。selenium + httpwatch,将是一个不错的解决方案。本文主要介绍,将httpwatch附加到selenium webdriver的方法。
IWebDriver driver = <Create Selenium Driver using existing profile>; // Don't use new FirefoxDriver()
// Set a unique initial page title so that HttpWatch can attach to it
string uniqueTitle = Guid.NewGuid().ToString();
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("document.title = '" + uniqueTitle + "';");
// Attach HttpWatch to the instance of the browser created through Selenium
Plugin plugin = control.AttachByTitle(uniqueTitle);
IWebDriver driver = <Create Selenium Driver using existing profile>; // Don't use new FirefoxDriver()
// Set a unique initial page title so that HttpWatch can attach to it
string uniqueTitle = Guid.NewGuid().ToString();
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("document.title = '" + uniqueTitle + "';");
// Attach HttpWatch to the instance of the browser created through Selenium
Plugin plugin = control.AttachByTitle(uniqueTitle);
我就照模照样的写个Python版的
IWebDriver driver = < Create Selenium Driver using existing profile >; // Don’t use new FirefoxDriver()
selenium Firefox 默认配置文件是webdriver_prefs.json,默认不加载所有的插件(add-ons)。所以,如果你忽略第一句,将发生以下报错:
plugin = self._control.AttachByTitle(uniqueTitle)
File "<COMObject HttpWatch.Controller>", line 2, in AttachByTitle
pywintypes.com_error: (-2147352567, '\xb7\xa2\xc9\xfa\xd2\xe2\xcd\xe2\xa1\xa3', (0, u'HttpWatch.Controller', u"AttachByTitle failed because no IE or Firefox page was found with the title 'd9f5f540-3227-4d8a-b928-daaf196e256b'. \r\n\r\nPlease check that HttpWatch is installed, enabled and working correctly in the target browser window. Also if you are using Selenium and Firefox make sure that you are using a copy of a profile that has HttpWatch enabled rather than a fresh profile created by 'new FirefoxDriver()'. For more information please refer to the Selenium/Firefox sample described in the HttpWatch Automation help - AttachByTitle failed", None, 0, -2147467259), None)
plugin = self._control.AttachByTitle(uniqueTitle)
File "<COMObject HttpWatch.Controller>", line 2, in AttachByTitle
pywintypes.com_error: (-2147352567, '\xb7\xa2\xc9\xfa\xd2\xe2\xcd\xe2\xa1\xa3', (0, u'HttpWatch.Controller', u"AttachByTitle failed because no IE or Firefox page was found with the title 'd9f5f540-3227-4d8a-b928-daaf196e256b'. \r\n\r\nPlease check that HttpWatch is installed, enabled and working correctly in the target browser window. Also if you are using Selenium and Firefox make sure that you are using a copy of a profile that has HttpWatch enabled rather than a fresh profile created by 'new FirefoxDriver()'. For more information please refer to the Selenium/Firefox sample described in the HttpWatch Automation help - AttachByTitle failed", None, 0, -2147467259), None)
那Firefox本地profile文件在哪,请查阅Firefox官方帮助: