程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Take you through Python automated testing (10) -- htmltestrunner generates test reports

編輯:Python

In the previous case , We have completed the basic ability of self-test , Can also complete the execution of the test , but It is not possible to output the test results in the form of reports , Next , Add the output of the test report to the previous test .

HTMLTestRunner Introduce

HTMLTestRunner yes python Standard library unittest An extension of , Can generate an intuitive test report . Before using it, you need to HTMLTestRunner.py File to python For installation purposes , For example, I Namely c:\Python27 Catalog .

Generate test reports

Let's talk about our previous LMD In the script of login test, let's take a look at HTMLTestRunner How it is used , take login_auto.py The content of is amended as follows :

#coding=utf-8
__author__ = 'Administrator'
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
import time
import unittest
import HTMLTestRunner
class login_test_case(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.maximize_window()
self.driver.get('http://www.chuangyijia.com/login')
def tearDown(self):
self.driver.quit()
def test_login(self):
self.driver.find_element_by_id('email').send_keys('[email protected]
qq.com')
self.driver.find_element_by_id('pwd').send_keys('a654321')
self.driver.find_element_by_id('submit').click()
#self.driver.implicitly_wait(5)
time.sleep(3)
WebDriverWait(self.driver,30).until(expected_conditions.visib
ility_of_element_located((By.CSS_SELECTOR,'.logo')))
print self.driver.title
is_title = expected_conditions.title_is(u' home page - Creationist ')
self.assertTrue(is_title(self.driver))
if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(login_test_case("test_login"))
Report_file =
u"H:\\pydj\\Lmd_auto_test\\Report\\Result.html"
Rf = file(Report_file,'wb')
Case_run =
HTMLTestRunner.HTMLTestRunner(stream=Rf,title=u'LMD Login test
',description=u" Test report output ")
Case_run.run(suite)

The above code is modified on the original basis , Joined the import HTMLTestRunner This sentence , also hinder

suite = unittest.TestSuite()
Create a test suite object
suite.addTest(login_test_case("test_login"))
Add the logged in test case to the test suite
Report_file = u"H:\\pydj\\Lmd_auto_test\\Report\\Result.html"
Set the location and file name of test report output
49
Rf = file(Report_file,'wb')
Use python Standard library file Open the test report file ,wb It is written in binary mode
open .
Case_run=HTMLTestRunner.HTMLTestRunner(stream=Rf,title=u'LMD
Login test ',description=u" Test report output ")
Create a HTMLTestRunner The object of , And use the above opened to output the test report
The object of the notification is passed into ,title yes html Of the report page title,description Test on
Description of the report
Case_run.run(suite)
Start running the test suite

Finally, thank everyone who reads my article carefully , The following online link is also a very comprehensive one that I spent a few days sorting out , I hope it can also help you in need !

These materials , For those who want to change careers 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful ……

If you don't want to grow up alone , Unable to find the information of the system , The problem is not helped , If you insist on giving up after a few days , You can click the small card below to join our group , We can discuss and exchange , There will be various software testing materials and technical exchanges .

Click the small card at the end of the document to receive it

Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .

Self study recommendation B Stop video :

Zero basis transition software testing :25 Days from zero basis to software testing post , I finished today , Employment tomorrow .【 Include features / Interface / automation /python automated testing / performance / Test Development 】

Advanced automation testing :2022B The first station is super detailed python Practical course of automated software testing , Prepare for the golden, silver and four job hopping season , After advanced learning, it soared 20K


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved