04、生成 HTMLTestRunner 测试报告
1>下载HTMLTestRunner.py文件,地址为:
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest
import time,sys
import HTMLTestRunner
reload(sys)
sys.setdefaultencoding("utf-8")
class Baidu(unittest.TestCase):
"""百度首页搜索测试用例"""
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://www.baidu.com"
def test_baidu_search(self):
driver = self.driver
print u"========【case_0001】 百度搜索============="
driver.get(self.base_url + "/")
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys(u"林志玲")
driver.find_element_by_id("su").click()
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
#必须要打印路径HTMLTestRunner才能捕获并且生成路径,\image\**.png 是获取路径的条件,必须这样的目录
pic_path=‘..\\result\\image\\‘+now+‘.png‘
print pic_path
driver.save_screenshot(pic_path)
time.sleep(2)
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
testunit = unittest.TestSuite()
testunit.addTest(Baidu("test_baidu_search"))
HtmlFile = "..\\result\\"+now+"HTMLtemplate.html"
print HtmlFile
fp = file(HtmlFile, "wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"百度测试报告", description=u"用例测试情况")
runner.run(testunit)
附件列表
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。