在之前的案例中,我们完成了自劢化测试的基本能力,也能完成测试的执行工作,但 是还没有做到将测试的结果以报表的形式输出,接下来,在之前的测试基础上加上测试报告的输出。
HTMLTestRunner 介绍
HTMLTestRunner 是 python 标准库 unittest 的扩展,可以生成一个直观的测试报告。 在使用之前需要将 HTMLTestRunner.py 文件放如到 python 的安装目弽下,例如我的 就是 c:\\Python27 目录。
生成测试报告
下我们在之前的 LMD 登陆测试的脚本中先来看看 HTMLTestRunner 是如何使用的,将 login_auto.py 的内容修改如下:
#coding=utf-8
__author__ = 'Administrator'
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
import time
import unittest
import HTMLTestRunner
class login_test_case(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.maximize_window()
self.driver.get('http://www.chuangyijia.com/login')
def tearDown(self):
self.driver.quit()
def test_login(self):
self.driver.find_e