Python+Unittest+HTMLTestRunner测试报告—百度个人中心实例
环境配置:https://blog.csdn.net/sevensolo/article/details/100125704
Unittest用法:https://blog.csdn.net/sevensolo/article/details/98202271
# -*- coding = utf-8 -*-
import unittest
import time
from selenium import webdriver
from HTMLTestRunner import HTMLTestRunner
url = "https://www.baidu.com"
class test_Baidu(unittest.TestCase):
def setUp(self):
self.broswer= webdriver.Chrome() # 启动浏览器。Unittest方法,执行之前调用
def tearDown(self): # 关闭浏览器。Unittest方法,用例执行完毕之后调用
self.broswer.quit()
def test_open(self):
"""打开浏览器"""
self.broswer.get(url)
time.sleep(1)
self.assertEqual("百度一下,你就知道", self.browser.title)
if __name__ == "__main__":
unittest.main()
· 这里我们使用了setUp