【概述】
Httpwatch 一款强大的网页数据分析工具。它可以捕捉http/https数据,查看底层的数据,包括headers、cookies、cache等。同时,记录发送请求、接收请的时间。Anyway,a good tool for you。
或许,你有一个需求,要在selenium进行页面功能测试的时候,你需要获取一些信息,如提交请求数据、接收请求数据、页面加载的时间等。selenium + httpwatch,将是一个不错的解决方案。本文主要介绍,将httpwatch附加到selenium webdriver的方法。
注意:
有关httpwatch的使用,请自行查看API文档:
http://apihelp.httpwatch.com/#Automation%20Overview.html
【selenium + httpwatch】
官方做法(JAVA版):
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版的
control = win32com.client.Dispatch('HttpWatch.Controller')
#driver=webdriver.Ie(executable_path="D:\\software\\IEDriverServer_Win32_2.28.0\\IEDriverServer.exe")
profile = webdriver.FirefoxProfile(r'C:\Users\X230\AppData\Roaming\Mozilla\Firefox\Profiles\68zb9g9a.default')
driver=webdriver.Firefox(firefox_profile=profile)
uniqueTitle = str(uuid.uuid4())
driver.get(url)
driver.execute_script('document.title = "' + uniqueTitle + '";')
plugin = control.AttachByTitle(uniqueTitle)
plugin.Log.EnableFilter(False)
plugin.Record()
#plugin.GotoURL(url)
plugin.Stop()
control = win32com.client.Dispatch('HttpWatch.Controller')
#driver=webdriver.Ie(executable_path="D:\\software\\IEDriverServer_Win32_2.28.0\\IEDriverServer.exe")
profile = webdriver.FirefoxProfile(r'C:\Users\X230\AppData\Roaming\Mozilla\Firefox\Profiles\68zb9g9a.default')
driver=webdriver.Firefox(firefox_profile=profile)
uniqueTitle = str(uuid.uuid4())
driver.get(url)
driver.execute_script('document.title = "' + uniqueTitle + '";')
plugin = control.AttachByTitle(uniqueTitle)
plugin.Log.EnableFilter(False)
plugin.Record()
#plugin.GotoURL(url)
plugin.Stop()
请留意官方版的第一句话(如下)。意思是,(如果使用Firefox)请不要使用默认的profile配置,需要使用Firefox本地profile配置。
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官方帮助:
https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data
然后,如下初始化driver即可:
driver=webdriver.Firefox(firefox_profile=profile)
分享到:
相关推荐
Selenium 2自动化测试实战 基于Python语言 企业批量购书 分享 关注商品举报 Selenium 2自动化测试实战 基于Python语言 这不仅是一本Selenium2自动化测试书,同时还是一本实用的Python基础编程书
本书介绍了如何用Python语言调用Selenium WebDriver接口进行自动化测试。主要内容为:基于Python 的 Selenium WebDriver 入门知识、Selenium Python脚本、使用unittest 编写单元测试、生成HTML格式的测试报告、元素...
虫师2016年10月的书,相当新
SELENIUM 2 自动化测试实战 基于PYTHON语言-------------------------------------------------------
selenium + python的自动化测试书籍,高清版,适合软件自动化测试人员,由浅入深,代码实例丰富,对自学者很有帮助
资源包括Selenium自动化测试:基于Python语言的文档以及每章节的代码
selenium2 python自动化测试 PDF学习 本PDF可以学习到如何进行Web自动化测试以多线程运行测试集,自动生成测试报告,最后完成后发送邮件等功能。
资源名称:SELENIUM 2 自动化测试实战 基于PYTHON语言内容简介:《Selenium 2自动化测试实战——基于Python语言》共分 14 章。第 1 章是自动化测试相关基础知识的介绍;第 2 章到第 10 章是《Selenium 2自动化测试...
向我或星标pythonSelenium使用Python Selenium进行GUI自动化测试了解更多: : 如何开始测试# Start containerdocker run -d --restart=always \ -v /tmp/screenshot:/tmp/screenshot \ -h selenium --name selenium...
资源包括Selenium自动化测试:基于Python语言的文档以及每章节的代码
Selenium 2自动化测试实战 基于Python语言 高清完整版
个人最近开始学习Selenium,但发现对应python的有用的资料奇少无比,于是 自己努力收集并整理了一些资料 学会搭建环境后的同学,建议先抛弃其他一切资料,先看一遍这个python资料,保证收益匪浅,基本上可以动手做...
虫师的:Selenium2+Python第二版 包含python介绍 web driver介绍 等等
selenium + python的自动化测试书籍,高清版,适合软件自动化测试人员,由浅入深,代码实例丰富,对自学者很有帮助
Selenium2+Python自动化测试实战Selenium2+Python自动化测试实战
SELENIUM 2 自动化测试实战 基于PYTHON语言-虫师
python+selenium自动化测试技术入门手册,不错的讲解。
selenium2 python自动化测试.pdf
python selenium 测试报告