• 【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)
  • 相关阅读:
    Selenium with Python 003
    测试计划编写要点
    【springboot】给你一份Spring Boot知识清单
    【小技巧】排名前 16 的 Java 工具类!
    【linux】tail 命令详解
    【linux】less 命令详解
    【小技巧】java的List分页
    【springboot】自动装配原理
    【springcloud】springcloud Greenwich SR4版本笔记
    【转】springcloud底层原理
  • 原文地址:https://www.cnblogs.com/paulwinflo/p/4612578.html
Copyright © 2020-2023  润新知