Python unitTest如何產生 HTML report?

 

 Python unitTest如何產生 HTML report?

下載

pip    install   nose

pip     install   nose-htmloutput

指令執行

nosetests  –with-html-output    GoogleSearch.py

 

GoogleSearch.py範例程式

[pastacode lang=”python” message=”” highlight=”” provider=”manual”]

import unittest
from __builtin__ import classmethod

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By


class HomePageTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # create a new Firefox session """
        #cls.driver = webdriver.Firefox()

        # Use PhantomJS
        cls.driver = webdriver.PhantomJS()
        cls.driver.implicitly_wait(30)
        cls.driver.maximize_window()

        # navigate to the application home page """
        cls.driver.get("http://www.google.com/")

    def test_search_field(self):
        # check search field exists on Home page
        self.assertTrue(self.is_element_present(By.NAME, "q"))

    def test_Google_page_title(self):
        # check search field exists on Home page
        self.assertEqual(self.driver.title, "Google")

    @classmethod
    def tearDownClass(cls):
        # close the browser window
        cls.driver.quit()

    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e:
            return False
        return True


if __name__ == '__main__':
    unittest.main(verbosity=2)

[/pastacode]

 

UnitestReport 結果

Python unittest Report

Leave a Reply

Your email address will not be published. Required fields are marked *