Tuesday 30 August 2011

HTML Report using HTMLTestRunner


Example –
from selenium import selenium
import HTMLTestRunner
import unittest, time

class main_script(unittest.TestCase):
    selenium = selenium("localhost", 4444, "*firefox","http://google.co.in")
    selenium.start()
    selenium.open("/")
    def test01_script(self):
        browser=self.selenium
        print "Open the google page"
        browser.type("q", "selenium RC")
        print "Enter the search test Selenium RC"
        browser.click("btnG")
        print "Click on Google Search button"
        browser.stop()
if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(main_script))
    dateTimeStamp = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("TestReport" + "_" + dateTimeStamp + ".html", 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
            stream=buf,
            title='Test the Report',
            description='Result of tests'
            )
    runner.run(suite)


Report – 

19 comments:

  1. Thankd lot..it is very useful for me.

    ReplyDelete
  2. Hi , I am getting unresolved import for HTMLTestRunner in Selenium WebDriver. Can u help me resolve this issue.

    -Krishna

    ReplyDelete
    Replies
    1. Hi,

      You need to download the HTMLTestRunner.py file from link (http://tungwaiyip.info/software/HTMLTestRunner.html). After that follow the below steps -Copy the “HTMLTestRunner.py” file in Python installation directory (ex - D:\Python27\Lib\site-packages).

      Now you will not get the unresolved import issue. Please let me know if you still face the issue.
      Regards,
      Dhirendra

      Delete
    2. Your input solved my issue, when working in Ubuntu OS

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Hi im using Mac,i had downloaded HTMLTestRunner.py file and saved in "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages" but still getting "unresolved import for HTMLTestRunner"

      Delete
  3. Hi,


    The example which given does not run correctly. it open the browser and close. i.e it does not call the test01_script() function at all. could you please fix it...

    Thanks
    HariRavi

    ReplyDelete
  4. Hi,
    It is not working for me. I am getting many errors. Can any help me on this?


    Thanks
    Gaurav Bhavsar

    ReplyDelete
  5. selenium = selenium("localhost", 4444, "*firefox","http://google.co.in")

    Please explain this statement... I can't understood..

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Is it possible to include each test steps in the report?

    ReplyDelete
  8. Hi ,

    Thanks for the help but i did little bit differently

    from selenium import webdriver
    from selenium import selenium
    import HTMLTestRunner
    import unittest, time
    from selenium.webdriver.common.keys import Keys

    class Test(unittest.TestCase):
    chrome = "Path where Chrome driver is kept " eg. C:\Browser_Webdrivers\chromedriver\chromedriver.exe

    brow = webdriver.Chrome(executable_path=chrome)
    brow.get("https://www.google.com")

    def test01(self):
    self.brow
    print "Open the Google Page"
    brow.find_element_by_name("q").send_keys(" Selenium RC")
    print "Enter the search test Selenium RC"

    brow.find_element_by_id("gbqfb").click()
    print "Click on Google Search button"

    brow.close()

    if __name__ == "__main__":

    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(Test))
    dateTimeStamp = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("Test Report" + "_" + dateTimeStamp + ".html", 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
    stream=buf,
    title='Test Report',
    description='Result of tests'
    )
    runner.run(suite)

    ReplyDelete
  9. I am getting file is not defined error. I am using python 3.4. Please help if you have solution for this. Has anyone tried executing this using python 3.4?

    ReplyDelete
    Replies
    1. I am getting same error while executing the code by using python 3.5

      Delete
  10. Thanks It is really Useful.Please keep up the good work..!!!
    Vishal Aggarwal
    http://testocean.blogspot.in

    ReplyDelete
  11. buf = file("TestReport" + "_" + dateTimeStamp + ".html", 'wb')

    getting msg that undefined variable file, please anyone help me

    ReplyDelete
  12. Nice information thank you,if you want more information please visit our link selenium Online course

    ReplyDelete