开发者

How can I generate html test report using python in my code

开发者 https://www.devze.com 2023-02-06 13:45 出处:网络
from selenium import seleniu开发者_如何学Gom import unittest, time, re import HTMLTestRunner class Untitled(unittest.TestCase):
from selenium import seleniu开发者_如何学Gom
import unittest, time, re
import HTMLTestRunner

class Untitled(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost",4444,"*iexplore","http://google.com.ua/")
        self.selenium.start()

    def test_untitled(self):
        sel = self.selenium
        sel.open("/")
        sel.type("q", "home")
        sel.click("btnG")
        sel.click("link=Welcome to Home.com")
        sel.wait_for_page_to_load("30000") 
        self.failUnless(sel.is_text_present("Results * for selenium rc"))

    def tearDown(self):
        time.sleep(25)
 self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

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


When I faced a similar problem I had to override TestResult and TestCase.defaultTestResult() to collect data into a number of lists convenient to me. Then you can use any template library (Jinja, Mako, etc) to turn it into HTML.


Can you please Try in

if __name__ == "__main__":
  testSuite = unittest.TestSuite(suites)
  runner = unittest.TextTestRunner(verbosity=1)
  filename = "Test1.html"
  output = open (filename,"wb")
  runner = HTMLTestRunner.HTMLTestRunner(
         stream=output,
         title="Test report"
     )
  runner.run(testSuite)
0

精彩评论

暂无评论...
验证码 换一张
取 消