Selenium+python-html Generating Report Code

Source: Internet
Author: User

Python automated tests generate HTML test reports

Htmltestrunner is an extension of the Python standard library UnitTest unit Testing framework, which generates easy-to-use HTML test reports.

Ubuntu Placement: Enter the Python3 command into Python interactive mode, with import sys and sys.path to view the native Python installation directory

[Email protected]:/home/ranxf# python3python 3.5.2 (default, Nov, 16:37:01) [GCC 5.4.0 20160609] on Linuxtype "Hel P "," copyright "," credits "or" license "for more information.>>> import sys>>> Sys.psys.path                 Sys.platform             sys.ps2sys.path_hooks           sys.prefix               sys.path_importer_cache  sys.ps1                  >>> sys.path[', '/usr/lib/python35.zip ', '/usr/lib/python3.5 ', '/usr/lib/python3.5/plat-x86_64-linux-gnu ', '/usr/lib/ Python3.5/lib-dynload ', '/usr/local/lib/python3.5/dist-packages ', '/usr/lib/python3/dist-packages ']

Copy the htmltestrunner.py file to the /usr/local/lib/python3.5/dist-packages directory as root.

[Email protected]:/usr/local/lib/python3.5/dist-packages# lsselenium  selenium-3.7.0.dist-info[email protected ]:/usr/local/lib/python3.5/dist-packages# cp/home/ranxf/Download/htmltestrunner.py. [Email protected]:/usr/local/lib/python3.5/dist-packages# lshtmltestrunner.py  Selenium  Selenium-3.7.0.dist-info

Import the module in interactive mode, if there is no error, then add success:

Instance: Iterates through all the use cases that begin with test under this path (/home/ranxf/python_web_unittest-master/test_case).

ImportUnitTest, TimeFrom HtmltestrunnerImportHtmltestrunner#Define the catalog of test cases as the current directory#Test_dir = './test_case '#Discover = Unittest.defaultTestLoader.discover (Test_dir, pattern= ' test*.py ')If__name__ = =‘__main__‘: Test_dir =‘/home/ranxf/python_web_unittest-master/test_case‘Test_report =‘/home/ranxf/python_web_unittest-master/report‘Discover = Unittest.defaultTestLoader.discover (Test_dir, pattern=‘test*.py‘)#Get the current time in a certain format now = Time.strftime ("%y-%m-%d%h_%m_%s")#Define a report storage path#filename = './' + now + ' result.html ' filename = test_report +'/' + now + 'result.html' fp = open (filename, 'wb') # define test report Runne R = Htmltestrunner (stream=fp, title='Web test report ', description=' use case execution: ') Runner.run (Discover) fp.close ()             

The test project directory structure is as follows:

[Email protected]:/home/ranxf/python_web_unittest-master#. ├──report├──runtest.py└──test_ Case    ├──test_baidu.py    └──test_youdao.py
Report: The directory where HTML reports are placed;
runtest.py: The main program that traverses the test case;
test_case: Use case placement Directory
Post-run directory structure:

.
├──report
│└──2017-12-26 15_56_59result.html
├──runtest.py
└──test_case

├──test_baidu.py
└──test_youdao.py

Selenium+python-html Generating Report Code

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.