这里我使用的是python selenium webdriver环境,浏览器驱动安装见selenium安装

1、下载HTMLTestRunner.py:http://tungwaiyip.info/software/HTMLTestRunner.html

  python3环境需要对该文件的六个地方进行修改,修改后放置python\Lib目录下

from selenium import webdriver
import HTMLTestRunner,unittest,time,os class BaiduTest(unittest.TestCase):
def setUp(self): #测试准备工作
self.driver = webdriver.Chrome() #加载驱动
self.driver.implicitly_wait(30) #隐式等待
self.base_url = "http://www.baidu.com" #url def test_baidu(self): #测试用例
driver = self.driver
print("========【case_0001】 百度搜索=============")
driver.get(self.base_url + "/") #get发送url
driver.find_element_by_id("kw").clear() #清空
driver.find_element_by_id("kw").send_keys("shuzf") #搜索shuzf
driver.find_element_by_id("su").click() #点击
time.sleep(5)#休息5s
self.assertEqual("shuzf_百度搜索", driver.title) # 断言判断是否相等
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
if not os.path.exists('result/image/'): os.makedirs('result/image/') #判断当前路径是否存在,没有则创建文件夹
pic_path = 'result/image/' + now + '.png'
driver.save_screenshot(pic_path) #生成图片 def tearDown(self): #释放资源
self.driver.quit() #退出 if __name__ == "__main__":
testunit = unittest.TestSuite() #构造测试套件
testunit.addTest(BaiduTest("test_baidu")) #添加测试用例 #HtmlFile = "c:/"+now+"run.html"
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
if not os.path.exists('result/'): os.makedirs('result/') #判断当前路径是否存在,没有则创建文件夹
HtmlFile = "result/" + now + ".html"
fp = open(HtmlFile, "wb") #生成报告
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title="百度测试报告", description="用例测试情况")
runner.run(testunit) #执行套件
fp.close() #关闭 #注意点1、浏览器驱动的安装 2,文件夹的生成

2,使用命令行执行文件,而不是pycharm

  >python demo.py

最新文章

  1. 未备案域名打开国内服务器上的网站(绑定国外空间并判断url后跳转引用)
  2. Knockout 官网翻译
  3. /px/em/rem/的区别
  4. JSP网站开发基础总结《四》
  5. C#版Windows服务安装卸载小工具-附源码
  6. Hadoop的shell脚本分析
  7. python 函数1
  8. css em
  9. LeetCode My Solution: Minimum Depth of Binary Tree
  10. 使用crontab,让linux定时执行shell脚本
  11. Spring知识点回顾(02)AOP
  12. c# 三种传参方式 in,out,ref
  13. [Android Pro] so 动态加载—解决sdk过大问题
  14. yum 快速安装centos7 mysql5.7
  15. B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表
  16. CSS中的通用字体
  17. Linux 编译时内存不足
  18. 精确的double加减乘除运算工具类
  19. async语法升级踩坑小记
  20. JavaScript中isPrototypeOf函数

热门文章

  1. 继承ConstraintLayout
  2. crfclust.bdb导致磁盘满
  3. jQuery中的serializer序列化—炒鸡好用
  4. error LNK2019: unresolved external symbol __vsnwprintf
  5. Win7 VS2019安装后创建C++工程失败解决
  6. [LeetCode] 477. Total Hamming Distance(位操作)
  7. Test Case Design Method - OATS
  8. C++ STL map容器值为指针时怎么释放内存
  9. Vue2.0响应式原理以及重写数组方法
  10. jmeter处理接口加密和解密