Steps to generate Htmltestrunner test reports--python+selenium Automation

Source: Internet
Author: User

Htmltestrunner is an extension of the UnitTest module of the Python standard library, as follows:

1. Installation

Environment: WINDOW8

Step: 1) http://tungwaiyip.info/software/HTMLTestRunner.html download htmltestrunner.py file
2) because I am using Python 3, so in the htmltestrunner.py file to make a change, the contents of the following changes:

Modify One:

Enter >>>import htmltestrunner >>> dir (htmltestrunner) in the Python shell to find Stringio (no module named Stringio), do not have this in 3, the 94th Line introduced the name to change, changed to import io,539 line to change to Self.outputbuffer = Io. Bytesio ()

Modify two: Run the program when there is an error, Attributeerror: ' Dict ' object has no attribute ' Has_key ' found that the Has_key was K dropped, all to 642 lines to do the modification, if not rmap.has_key (CLS): Need to replace if not

CLS in Rmap: (Change the line, space, etc. do not get rid of the original format)

Modified three:

Run, continue to have an error: ' str ' object has no attribute ' decode ' alas, it seems to be 3 in the face of the character operation, Decode has been removed. Positioning, reported in 772 lines, UE = E.decode (' latin-1 '), then do not need decode

Operation, directly to the UE = e, the other 766 there are similar UO = O.decode (' latin-1 '), can not move first to keep;

Modified four:

Continue to run, found still in the tangled data type of the error: output = Saxutils.escape (Uo+ue), Typeerror:can ' t concat bytes to str bytes and STR cannot be directly linked, Then 778 lines of content Escape (Uo+ue) has a processing "dumb way": all changed to STR, can be modified to the content of escape (str (UO) +ue)

Modified Five: (Here is the last change)

The program is already running mostly, but at the end there is an error:

Print >>sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime)

typeerror:unsupported operand type (s) for >>: ' Builtin_function_or_method ' and ' rpcproxy '

I believe that many people who have just touched 3.x understand that 2 and 3 print is very different, then in 3, print behind

is not with >> such, so to 631 lines, the print statement modified, the original is print >>sys.stderr, ' \ntime

Elapsed:%s '% (self.stoptime-self.starttime), can be changed to print (Sys.stderr, ' \ntime Elapsed:%s '% ( Self.stoptime-self.starttime)) Save the htmltestrunner.py after each modification. In addition, in 3, open the local file requires FP =open (filename, ' WB '), do not use file again; Fp.close () Closed

2. Verify that you added the success

Importing htmltestrunner.py packages in Python interactive mode

>>import Htmltestrunner

>>

Add success when the above message appears

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Examples of use are as follows:

#coding: Utf-8

From test_case Import Search
From test_case import setting
Import Htmltestrunner
Import UnitTest
Import Sys

Testunit = UnitTest. TestSuite ()
Testunit.addtest (Unittest.makesuite) (search. Baidu_search))
Testunit.addtest (Unittest.makesuite (setting. Setbai))

filename = ' e:\\study_code\\testing\\src\\result.html '
fp = open (filename, ' wb+ ')
Runner = Htmltestrunner.htmltestrunner (stream=fp,title= ' Baidu Search test Report ', description= ' use case execution ')

Runner.run (Testunit)

Steps to generate Htmltestrunner test reports--python+selenium Automation

Related Article

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.