HTMLTestRunner测试报告问题,求大神指点
用python自带的IDLE执行脚本,能正常生成html测试报告。但是同样的代码,在eclipse + pydev中执行,就是没法生成html测试报告,这会是什么原因呢?#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 Bing(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.bing.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_bing_search(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("sb_form_q").send_keys("selenium webdriver")
driver.find_element_by_id("sb_form_go").click()
time.sleep(2)
driver.close()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
testunit = unittest.TestSuite()
testunit.addTest(Bing("test_bing_search"))
filename = "E:\\result1.html"
fp = file(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
title=u'必应搜索测试报告',
description=u'用例执行情况:')
runner.run(testunit)
在论坛里也看到有人碰到类似的问题,但是没有解决方案,求大神解答,谢谢!
http://bbs.51testing.com/thread-1046110-1-1.html
#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 Bing(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.bing.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_bing_search(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("sb_form_q").send_keys("selenium webdriver")
driver.find_element_by_id("sb_form_go").click()
time.sleep(2)
driver.close()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
testunit = unittest.TestSuite()
testunit.addTest(Bing("test_bing_search"))
filename = "E:\\result1.html"
fp = file(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
title=u'必应搜索测试报告',
description=u'用例执行情况:')
runner.run(testunit) 看看文件的编码格式是否和之前的一样,如不同,请改成一样的 w_d775 发表于 2015-9-7 13:46
看看文件的编码格式是否和之前的一样,如不同,请改成一样的
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
在别的IDE是可能报编码错误的问题,加了上面的代码问题能解决。
不过eclipse中加了后,还是没法生成。
倒不是说eclipse压根没法生成,比如下面的代码就OK,真是奇怪。
#coding=utf-8
import unittest
import HTMLTestRunner
class Testlist(unittest.TestCase):
def test_1(self):
print "test1"
def test_2(self):
print "test2"
def suiting():
filename ="d:\\result.html"
fp = file(filename,"wb")
suit = unittest.TestSuite()
suit.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(Testlist))
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="testing result",description="trying")
runner.run(suit)
suiting()suiting()是必须加的
页:
[1]