Since Python3 has not supported Htmltestrunner anymore,
Neither Pycharm nor PIP can be successfully installed,
So can only go to https://pypi.python.org/pypi/HTMLTestRunner manual download,
Put the htmltestrunner.py file into the Lib folder under the Python3 installation directory;
There's one more place to be aware of,
Python3 already does not support the file method,
should use open!.
A lot of pits ...
New testcase.py:
import UnitTest
from time import sleep
from selenium import webdriver
Class Searchtestcase ( UnitTest. TestCase):
def setUp (self):
Self.driver = Webdriver. Firefox ()
Self.driver.maximize_window ()
Self.driver.get ("https://www.baidu.com/")
Sleep (2
def Test_searchchina (self):
"" "Baidu searches China for test case" ""
Self.driver.find_element_by_xpath (".//*[@ id= ' kw '). Send_keys ("China")
Self.driver.find_element_by_xpath (".//*[@id = ' su ']"). Click ()
Sleep (2)
result = Self.driver.find_element_by_xpath (".//*[@id = ' 1 ']/h3/a"). Text
Self.assertequal (Result, "China _ Hundred ")
def tearDown (self):
Self.driver.close ()
Self.driver.quit ()
If __name__ = = ' _ _main__ ':
Unittest.main ()
and then new htmlreport.py:
Import Htmltestrunner
Import UnitTest
From time import strftime, localtime, time
From TestCase import searchtestcase
Suite = UnitTest. TestSuite ()
# Get the instance object of Testsuite
Suite.addtest (Searchtestcase ("Test_searchchina"))
# Add test Cases to the test container
now = strftime ("%y-%m-%m-%h_%m_%s", LocalTime (Time ()))
# Get current time
filename = now + "test.html"
# file name
fp = open (filename, "WB")
# Open the file in binary mode and write the result
Runner = Htmltestrunner.htmltestrunner (
STREAM=FP,
verbosity=2,
Title= "The title of the test Report",
description= "Details of the test report")
Runner.run (Suite)
Fp.close ()
Run a hand,
The HTML file is generated at the root of the current project,
Open it:
Selenium (Python) generates HTML test reports