• HTMLTestRunner生成空白resault.html


    发现一奇葩问题,用idle或pyscripter执行脚本,生成的是空白html,通过cmd,进入脚本目录执行python xx.py,却能生成测试报告。

    HTMLTestRunner 例子

    #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
    
    
    class My_Test_Suite(unittest.TestCase):
        u'''打印百度、google标题'''
        def setUp(self):
            self.driver = webdriver.Ie()
            self.driver.implicitly_wait(30)
            self.verificationErrors = []
            self.accept_next_alert = True
    
        def test_baidu(self):
            u'''打开百度'''
            driver = self.driver
            driver.get("http://www.baidu.com")
            print u'当前网页是:',driver.title
            driver.close()
    
        def test_google(self):
            u'''打开google'''
            driver = self.driver
            driver.get("http://www.google.com.hk")
            print u'当前网页是:',driver.title
    
        def tearDown(self):
            self.driver.quit()
            self.assertEqual([], self.verificationErrors)
    
    if __name__ == "__main__":
    
        #定义一个单元测试容器
        testunit=unittest.TestSuite()
    
        #将测试用例加入到测试容器中
        testunit.addTest(My_Test_Suite("test_baidu"))
        testunit.addTest(My_Test_Suite("test_google"))
    
        #定义个报告存放路径,支持相对路径
        filename = 'G:\seleniums\result.html'
    
        fp = file(filename, 'wb')
        #定义测试报告
        runner =HTMLTestRunner.HTMLTestRunner(stream=fp,title=u'测试报告',description=u'用例执行详情::')
    
        #运行测试用例
        runner.run(testunit)

  • 相关阅读:
    POJ 1611
    [Erlang24]使用zotonic搭建网站记录
    [Erlang23]怎么有效的遍历ETS表?
    [Erlang22]如何按规则位数输出数字
    [Git00] Pro Git 一二章读书笔记
    十分钟用HTML&CSS让博客园变得高大上
    [Erlang21]Erlang性能分析工具eprof fporf的应用
    [Erlang20]一起攻克Binary
    [Erlang19]Erlang的config文件读取效率问题
    [Erlang18]教练!又发现Erlang Shell里面的神奇函数一只
  • 原文地址:https://www.cnblogs.com/rmb-mylove123/p/3646900.html
Copyright © 2020-2023  润新知