51Testing软件测试论坛

标题: selenium + python 执行的 HTMLTestRunner测试报告没有内容 [打印本页]

作者: rxq    时间: 2015-11-25 22:22
标题: selenium + python 执行的 HTMLTestRunner测试报告没有内容
本帖最后由 rxq 于 2015-11-25 23:01 编辑

执行过程中没有报错,也生成了HTML文件,但文件里没有内容。
代码如下:
TestCase 文件,login.py
__author__ = 'Amy Liu'
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import unittest
import time


class login(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.accept_next_alert = True
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.verificationErrors = []
self.accept_next_alert = True
self.base_url = 'http://www.haosou.com'
def test_signin(self):
driver = self.driver
        try:
driver.get(self.base_url + '/')
time.sleep(2)
driver.find_element_by_id("input").send_keys("su")
driver.find_element_by_id("search-button").click()
result = driver.find_element_by_id("keyword").get_attribute('value')
if result == "su":
print("Test Passed! Test Result is: " + result)
flag = True
        except Exception as e:
falg = False
print("Test Failed")
print(e)
driver.get_screenshot_as_file("D:\\Program Files\\NM.bmp")
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)



执行用例文件,run_case.py
import HTMLTestRunner
import sys
import time
# should import this if use method (1)
# from Demo import Login
import unittest
from Demo1.Login import login


# Get current time
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
# Define the report path
filename = "d:\\result " + now + '.html'
result_file = open(filename, "wb")
runner = HTMLTestRunner.HTMLTestRunner(
stream=result_file,
    title="Test Result",
    description="Test cases execute result")
if __name__ == "__main__":
suite = unittest.TestSuite()
# (1) add all test cases from Login.py
# suite.addTest(unittest.makeSuite(Login.login))
# (2) add test case one by one
suite.addTest(login("test_signin"))
runner = unittest.TextTestRunner()
runner.run(suite)
result_file.close()
time.sleep(6)




log 如下:

C:\Python34\python.exe I:/QA/Python/workspace/Demo1/run_case.py
Test Passed! Test Result is: su
.
----------------------------------------------------------------------
Ran 1 test in 6.632s

OK




作者: rxq    时间: 2015-11-25 22:33
本帖最后由 rxq 于 2015-11-25 23:00 编辑

[img]file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\979961272\QQ\WinTemp\RichOle\~CCLJUXP067~Y7CWZYA%([L.png[/img]


作者: 冰薄荷    时间: 2016-2-13 23:30
不知道 你解决这个问题了吗? 我也遇到了。我是用的也是python  3.4。不知道是不是兼容问题




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2