Objective
In the Python selenium2 automated test process, a suitable report is required, and the Htmltestrunner module provides us with a good report generation function.
What is Htmltestrunner
Htmltestrunner is an extension of the UnitTest module of the Python Standard library. It produces beautiful HTML format test reports
Htmltestrunner Installation
: Https://pypi.python.org/pypi/HTMLTestRunner
Placed in the current Python project as a module of your own.
Application examples
#-*-Coding:utf-8-*-
__author__ = U ' bitter leaves '
From selenium import Webdriver
Import UnitTest
Import Htmltestrunner
Import Sys
From time import sleep
Reload (SYS)
Sys.setdefaultencoding ("Utf-8")
Class Baidutest (UnitTest. TestCase):
"" "Baidu Home Search test Case" ""
def setUp (self):
Self.driver = Webdriver. Chrome ()
Self.driver.implicitly_wait (30)
Self.base_url = u "http://www.baidu.com"
def test_baidu_search (self):
Driver = Self.driver
Print U "start [case_0001] Baidu Search"
Driver.get (Self.base_url)
# Verify Title
Self.assertequal (Driver.title, U "Baidu a bit, you will know")
driver.find_element_by_id ("kw"). Clear ()
driver.find_element_by_id ("kw"). Send_keys (U "open source test")
driver.find_element_by_id ("su"). Click ()
Sleep (3)
# Verify Search Result title
Self.assertequal (Driver.title, U "Open source Excellent test _ Baidu search")
def tearDown (self):
Self.driver.quit ()
if __name__ = = ' __main__ ':
Testunit = UnitTest. TestSuite ()
Testunit.addtest (baidutest (' Test_baidu_search '))
# define report Output path
Htmlpath = u "c:\\testreport.html"
fp = file (Htmlpath, "WB")
Runner = Htmltestrunner.htmltestrunner (STREAM=FP, title=u "Baidu Test", description=u "test Case results")
Runner.run (Testunit)
Fp.close ()
Report effect
Python selenium2 sample-Generate Htmltestrunner test report