About python-generating Htmltestrunner test reports

Source: Internet
Author: User

Htmltestrunner is an extension of the Python standard library's UnitTest module, which generates test reports for HTML.
1. First, the next htmltestrunner.py file, the downloaded file into the ... \python\lib directory

2. Introduce the Htmltestrunner package in idle, if there is no error (red), then add success, such as:

Second, all_tests.py

================

#coding =utf-8
" "
Project: Execute multiple Test cases through a test suite and generate reports
" "
Import Htmltestrunner
Import UnitTest
Import Os,time

test = "D:\\Program files\\pydemo\\unit\\package\\test_case"
def createsuite1 ():
Testunit=unittest. TestSuite ()
discover=unittest.defaulttestloader.discover (test,pattern= ' start_*.py ', Top_level_dir=none)
For Test_suite in Discover:
For test_case in Test_suite:
testunit.addtests (test_case)
print (testunit)
return Testunit
Now = Time.strftime ("%y-%m-%d%h_%m_%s", Time.localtime ())
filename= "D:\\Program files\\pydemo\\unit\\package\\" +now+ "_result.html "
fp=open (filename, ' WB ')

Runner=htmltestrunner.htmltestrunner (
STREAM=FP,
title=u ' search function test report ',
description=u ' use case execution: ')

Runner.run (Createsuite1 ())
#关闭文件流, no, the generated report is empty.
fp.close ()

================

Test cases under the test directory

start_baidu.py

----------------------------

# Coding=utf-8
" "
Project: Login to Baidu test case
" "
From Selenium import Webdriver
import UnitTest, time

class Baidutest (unittest. TestCase):
def setUp (self):
self.driver = Webdriver. Chrome ()
self.driver.implicitly_wait (#隐性等待时间为30秒)
Self.base_url = "https://www.baidu.com"

def test_baidu_search (self):
u "" "Baidu Search" ""
Driver = Self.driver
Driver.get (Self.base_url + "/")
driver.find_element_by_id ("kw"). Clear ()
driver.find_element_by_id ("kw"). Send_keys ("UnitTest")
driver.find_element_by_id ("su"). Click ()
Time.sleep (3)
Title=driver.title
self.assertequal (title, U "unittest_ Baidu search")

def test_baidu_set (self):
u "" "Baidu Set" ""
Driver=self.driver
driver.get (self.base_url+ "/gaoji/preferences.html")
m=driver.find_element_by_name ("NR")
time.sleep (1)
M.find_element_by_xpath ("//option[@value = ']"). Click ()
time.sleep (1)

def tearDown (self):
self.driver.quit ()

if __name__ = = "__main__":
Unittest.main ()

----------------------------

Third, run the all_tests.py generated report as follows

About python-generating Htmltestrunner test reports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.