Python selenium2 sample-Generate Htmltestrunner test report

Source: Internet
Author: User

Objective

In the Python selenium2 automated test process, a suitable report is required, and the Htmltestrunner module provides us with a good report generation function.

What is Htmltestrunner

Htmltestrunner is an extension of the UnitTest module of the Python Standard library. It produces beautiful HTML format test reports

Htmltestrunner Installation

: Https://pypi.python.org/pypi/HTMLTestRunner

Placed in the current Python project as a module of your own.

Application examples

#-*-Coding:utf-8-*-

__author__ = U ' bitter leaves '

From selenium import Webdriver

Import UnitTest

Import Htmltestrunner

Import Sys

From time import sleep

Reload (SYS)

Sys.setdefaultencoding ("Utf-8")

Class Baidutest (UnitTest. TestCase):

"" "Baidu Home Search test Case" ""

def setUp (self):

Self.driver = Webdriver. Chrome ()

Self.driver.implicitly_wait (30)

Self.base_url = u "http://www.baidu.com"

def test_baidu_search (self):

Driver = Self.driver

Print U "start [case_0001] Baidu Search"

Driver.get (Self.base_url)

# Verify Title

Self.assertequal (Driver.title, U "Baidu a bit, you will know")

driver.find_element_by_id ("kw"). Clear ()

driver.find_element_by_id ("kw"). Send_keys (U "open source test")

driver.find_element_by_id ("su"). Click ()

Sleep (3)

# Verify Search Result title

Self.assertequal (Driver.title, U "Open source Excellent test _ Baidu search")

def tearDown (self):

Self.driver.quit ()

if __name__ = = ' __main__ ':

Testunit = UnitTest. TestSuite ()

Testunit.addtest (baidutest (' Test_baidu_search '))

# define report Output path

Htmlpath = u "c:\\testreport.html"

fp = file (Htmlpath, "WB")

Runner = Htmltestrunner.htmltestrunner (STREAM=FP, title=u "Baidu Test", description=u "test Case results")

Runner.run (Testunit)

Fp.close ()

Report effect

Python selenium2 sample-Generate Htmltestrunner test report

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.