Selenium Python HTMLTestRunner报告输出为空白

时间:2016-04-13 15:24:53

标签: python-2.7 selenium selenium-webdriver

我正在使用HTMLtestRunner作为我的Selenium Python测试结果报告。 测试完成时生成报告文件,但是当我打开文件时,它是空白的。该文件为0kb
没有任何内容写入报告文件。

我的测试套件代码实现是:

import sys, os
import unittest
from HTMLTestRunner2 import HTMLTestRunner
from Utilities.HelperMethods import get_datetime_now
import Regression_TestCase.RegressionProject_TestCase2


class Test_Suite(unittest.TestCase):
    def test_main(self):
        # suite of TestCases
        self.suite = unittest.TestSuite()
        test_result_dir = os.path.join(
            r"C:\\Webdriver\\ClearCore Regression Test\\ClearCore - Regression Test\\TestReport\\")  # Test report goes here

        # open the report file
        outfile = file(test_result_dir + "\TestReport_" + get_datetime_now() + ".html", "wb")

        runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
                                               title='Test Report',
                                               description='Selenium - ClearCore Regression project automated test')

        self.suite.addTests([
            unittest.defaultTestLoader.loadTestsFromTestCase(
                Regression_TestCase.RegressionProject_TestCase2.RegressionProject_TestCase2)
        ])
        runner = unittest.TextTestRunner()
        runner.run(self.suite)


import unittest

if __name__ == "__main__":
    # unittest.main()
    HTMLTestRunner.main()

我的RegressionProject_TestCase2片段是:

from Base.BaseTestCase import BaseTestCase
from HTMLTestRunner2 import HTMLTestRunner
import os
from Locators import Globals
# More imports

class RegressionProject_TestCase2(BaseTestCase):

### Test Login ###

def test_000001_a1_login_empty_user_id_and_empty_password(self):
    try:
        print "*** testlogin_empty_user_id_and_empty_password ***"
        self.login_page.user_login_invalid(Globals.login_username_blank, Globals.login_password_empty)
        self.assertTrue(self.login_page.is_invalid_user_error_text_displayed(), "login_empty_user_id_and_empty_password failed. Please see log for details")
    except Exception:
        base_page = BasePage(self.driver)
        base_page.save_screenshot("Test login_empty_user_id_and_empty_password")
        raise

### Lots more test cases

if __name__ == "__main__":
#unittest.main()
HTMLTestRunner.main()

为什么报告输出空白?有些人帮助我使用我的测试套件来生成HTML报告。

谢谢Riaz

1 个答案:

答案 0 :(得分:0)

我已将代码移至另一台服务器,并重新编写测试套件以创建htmltestRunner HTML报告。它现在对我有用。

我的测试套件实现是:

import sys
import unittest
from HTMLTestRunner2 import HTMLTestRunner
from Utilities.HelperMethods import get_datetime_now
import os
import unittest
import Regression_TestCase.RegressionProjectEdit_TestCase


class Test_Suite(unittest.TestCase):
    def test_main(self):


        tests_regression = unittest.TestLoader().loadTestsFromTestCase(
            Regression_TestCase.RegressionProjectEdit_TestCase.RegressionProject_TestCase_Project_Edit)


        regression_tests = unittest.TestSuite([tests_regression])


def suite():
    """
        Gather all the tests from this module in a test suite.
    """
    test_suite = unittest.TestSuite()
    test_suite.addTest(unittest.makeSuite(Regression_TestCase.RegressionProjectEdit_TestCase.RegressionProject_TestCase_Project_Edit))
    return test_suite


mySuit = suite()

# output to a file
test_result_dir = os.path.join(
    r"E:\\test_runners 2 edit project\\selenium_regression_test_5_1_1\\TestReport\\")


# open the report file
outfile = file(test_result_dir + "\ClearCore501_Automated_GUI_TestReport.html", "wb")

# configure HTMLTestRunner options
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
                                       title='Test Report',
                                       description='Selenium - ClearCore 501 Regression edit project automated test')

# run the suite using HTMLTestRunner
runner.run(mySuit)

if __name__ == "__main__":
    # unittest.main()
    HTMLTestRunner.main()