Appium+python+htmltestrunner

Source: Internet
Author: User

For automation, test reports are required, and in an agile team, members of the team need to automate the test report to determine the overall quality of the system and the next Test strategy. The Unit Test library generates test output to the console window, but the results look more laborious, obviously, the output of the console log is not a good note, so the good note is to generate the test report of the HTML page, so the report looks clearer, fortunately UnitTest the htmltestrunner.py of the Unit Test Library extension , you can generate automated reports for HTML.

First, htmltestrunner.py

First, download the htmltestruner.py file.  
Source address: http://tungwaiyip.info/software/HTMLTestRunner.html 
This is for the Python2.7 version, so for python3.x use, Need to change a few places. Http://www.bubuko.com/infodetail-529431.html.  
specific changes are as follows:  
Line 94th, change import Stringio to import io 
Line No. 539, Self.outputbuffer = Stringio.stringio () modified to self.outputbuffer= IO. Stringio ()  
Line No. 631, change print >> sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime) to print ( Sys.stderr, ' \ntimeelapsed:%s '% (self.stoptime-self.starttime))  
Line No. 642, if not Rmap.has_key (CLS): Modify to If Notcls in rmap: 
Line No. 766, modify UO = O.decode (' latin-1 ') to UO = e 
Line No. 775, change UE = E.decode (' latin-1 ') to UE = E &NBSP
Line No. 778, output = Saxutils.escape (Uo+ue), modified to output = Saxutils.escape (str (UO) +STR (UE)),

The above changes, save successfully, then put htmltestrunner.py into the C:\Python34\Lib directory, run cmd, enter Python, importing import Htmltestrunner, without any error message, indicates success, see:

htmltestrunner.py implementation of the HTML test report, see the following test instance code:

#coding: Utf-8

Fromselenium Import Webdriver

FromTime Import Sleep,time,ctime

Import UnitTest

FromPage Import *

Import threading

Import Htmltestrunner

Class Demopage (UnitTest. Testcase,basepage.page):

def setUp (self):

Self.driver=webdriver. Firefox ()

Self.driver.implicitly_wait (30)

Self.driver.maximize_window ()

Self.driver.get (' http://www.baidu.com ')

def testtitle (self,value= ' TestData '):

Self.asserttrue (Self.driver.title in Self.getxmldata (value))

def testurl (self):

Print Self.driver.current_url

def tearDown (self):

Self.driver.close ()

Self.driver.quit ()

if__name__== ' __main__ ':

Suite=unittest.makesuite (Demopage)

#定义自动化报告目录

Filename= ' d:\\git\\pycharm\\seleniumhq\\test-report\\report.html '

Fp=file (filename, ' WB ')

Runner=htmltestrunner.htmltestrunner (

STREAM=FP,

Title=u ' Automated test Report ',

Description=u ' Automated test Report '

)

Runner.run (Suite)

After successful execution, automated test reports in the D:\\git\\pycharm\\seleniumhq\\test-report directory report.html, open report.html files, you can see the following automated test reports:

Appium+python+htmltestrunner

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.