【selenium】HTMLTestRunner测试报告生成

__author__ = ‘Administrator‘
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import HTMLTestRunner #引入 HTMLTestRunner 包
class Baidu (unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.baidu.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    def test_baidu_search(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("kw").send_keys("163")
        driver.find_element_by_id("su").click()
        time.sleep(2)
        driver.close()
        #百度设置用例
    def test_baidu_set(self):
        driver = self.driver
        #进入搜索设置页
        driver.get(self.base_url + "/gaoji/preferences.html")
        #设置每页搜索结果为 100 条
        driver.implicitly_wait(30)
        m=driver.find_element_by_xpath(".//*[@id=‘gxsz‘]/tbody/tr[4]/td[2]/select")
        m.find_element_by_xpath("//option[@value=‘50‘]").click()
        time.sleep(5)
        #保存设置的信息
        driver.find_element_by_xpath(".//*[@id=‘gxszButton‘]/input[1]").click()
        time.sleep(2)
        driver.switch_to_alert().accept()
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
    #定义一个单元测试容器
    testunit=unittest.TestSuite()
    #将测试用例加入到测试容器中
    testunit.addTest(Baidu("test_baidu_search"))
    testunit.addTest(Baidu("test_baidu_set"))
    #定义个报告存放路径,支持相对路径
    filename = ‘D:\\report\\result.html‘
    fp = file(filename, ‘wb‘)
    #定义测试报告
    runner =HTMLTestRunner.HTMLTestRunner(
    stream=fp,
    title=u‘百度搜索测试报告‘,
    description=u‘用例执行情况:‘)
    #运行测试用例
    runner.run(testunit)
时间: 2025-01-12 09:04:13

【selenium】HTMLTestRunner测试报告生成的相关文章

记Selenium HTMLTestRunner 无法生成测试报告的总结

使用Python ,HTMLTestRunner 生成测试报告时,遇到很奇怪的问题,明明运行的结果,没有任何报错,就是不生成测试报告,纠结好久.google+baidu搜索结果也不满意,最后终于解决,先总结下. 代码示例 """ OS:W7 64位 IDE:Pycharm Py:Python2.7.11 """ # -*- coding: utf-8 -*- __Author__ = "xiewm" import time f

Selenium HTMLTestRunner 无法生成测试报告的总结

使用Python ,HTMLTestRunner 生成测试报告时,遇到很奇怪的问题,明明运行的结果,没有任何报错,就是不生成测试报告,纠结好久.google+baidu搜索结果也不满意,最后终于解决,先总结下. 代码示例 #coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom s

转 生成 HTMLTestRunner 测试报告

转自:http://www.cnblogs.com/hero-blog/p/4128575.html 04.生成 HTMLTestRunner  测试报告 1.HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展.它生成易于使用的 HTML 测试报告 1>下载HTMLTestRunner.py文件,地址为: http://tungwaiyip.info/software/HTMLTestRunner.html Windows平台: 将下载的文件放入...\P

Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告2(使用PyCharm )

1.说明 在我前一篇文件(Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使用IDLE ))中简单的写明了,如何生产测试报告,但是使用IDLE很麻烦,而且在实际的项目中也不方便,所以,查了很多资料来研究如何在PyCharm中生成测试报告,故此记录一下(命名什么的不规范就不要纠结了). 2.步骤 第一步:下载HTMLTestRunner.py 参考:Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使

selenium基础(生成测试报告)

测试报告 生成HTML测试报告 下载HTMLTestRunner.py包 下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html 下载后,把HTMLTestRunner.py 文件复制到Python 安装路径下的lib文件夹中即可. 引入包的方式:from HTMLTestRunner import HTMLTestRunner 在python3中用HTMLTestRunner.py报importError“:No module name

Python 同一文件中,有unittest不执行“if __name__ == '__main__”,不生成HTMLTestRunner测试报告的解决方案

1.问题:Python中同一个.py文件中同时用unittest框架和HtmlReport框架后,HtmlReport不被执行. 2.为什么?其实不是HtmlReport不被执行,也不是HtmlReport不生成测试报告,是因为if __name__ == '__main__'中的代码根本没执行好嘛! 3.解决方案的来源:因为最开始我的main代码中没有写print打印语句.没有生成HTML报告,我也在网上找了很久的方法,后来才怀疑是不是没有运行main方法,于是写了个print语句,果然没有运

HTMLTestRunner测试报告中文乱码问题解决

在学习python selenium自动化测试学习中遇到HTMLTestRunner测试报告出现乱码的问题 Test Group/Test case Count Pass Fail Error View baidu.Baidu 1 1 0 0 Detail test_baidu_search: 百度搜索 pass [x] pt1.1: [Error 32] : 'c:\\users\\zhengb~1\\appdata\\local\\temp\\tmpmoado1\\AddonInstalle

Python3之HTMLTestRunner测试报告美化

前面我们讲到过在做自动化测试或单元测试的时候使用HTMLTestRunner来生成测试报告,并且由于Python2 和 Python3 对于HTMLTestRunner的支持稍微有点差异,所以我们将HTMLTestRunner进行了改造,从而适配Python3,详细改造步骤可以参考:HTMLTestRunner修改成Python3版本 但是改造后的HTMLTestRunner生成的测试报告不是特别的美观,所以我又对HTMLTestRunner进行了进一步的改造,主要是做一些美化. 美化之前的测试

Robotium自动化测试报告生成

使用Robotium进行测试的时候,要想可以导出可视的测试结果,可以使用junitreport来实现junitreport下载地址:https://github.com/jsankey/android-junit-report 我们按照之前使用Robotium的编写测试步骤来执行,重复的这里不再赘述. 1. 将junitreport添加到工程的libs目录中 2. 将junitreport-xxxx.jar添加到build_path中(右键此文件,Build Path->add to build