百度为例
from selenium import webdriver
import unittest
import time
import os
class baidutest(unittest.TestCase):
def setUp(self):
chromedriver = "C:/Users/LX/AppData/Local/Google/Chrome/Application/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
self.browser = webdriver.Chrome(chromedriver)
self.browser.get("http://www.baidu.com")
def test_baidu(self):
self.browser.find_element_by_id("kw").send_keys("selenium")
self.browser.find_element_by_id("su").click()
time.sleep(3)
title = self.browser.title
self.assertEqual(title,u"selenium_百度搜索")
def tearDown(self):
self.browser.quit()
if __name__ == "__main__":
unittest.main()
使用HTMLTestRunner报告美化并调用执行测试用例
import unittest
import baidu
import HTMLTestRunner
suite = unittest.TestSuite()
suite.addTest(baidu.baidutest('test_baidu'))
fp = open("result.html", 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream = fp,title = u'自动化执行测试报告',description=u'用例执行情况')
if __name__ == "__main__":
runner.run(suite)
来源:CSDN
作者:qq_25495627
链接:https://blog.csdn.net/qq_25495627/article/details/104551598