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 –
Thankd lot..it is very useful for me.
ReplyDeleteHi , I am getting unresolved import for HTMLTestRunner in Selenium WebDriver. Can u help me resolve this issue.
ReplyDelete-Krishna
Hi,
DeleteYou 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
Your input solved my issue, when working in Ubuntu OS
DeleteThis comment has been removed by the author.
DeleteHi 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"
DeleteHi,
ReplyDeleteThe 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
Hi,
ReplyDeleteIt is not working for me. I am getting many errors. Can any help me on this?
Thanks
Gaurav Bhavsar
selenium = selenium("localhost", 4444, "*firefox","http://google.co.in")
ReplyDeletePlease explain this statement... I can't understood..
This comment has been removed by the author.
ReplyDeleteIs it possible to include each test steps in the report?
ReplyDeleteHi ,
ReplyDeleteThanks 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)
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?
ReplyDeleteI am getting same error while executing the code by using python 3.5
DeleteI'm getting same error
DeleteThanks It is really Useful.Please keep up the good work..!!!
ReplyDeleteVishal Aggarwal
http://testocean.blogspot.in
buf = file("TestReport" + "_" + dateTimeStamp + ".html", 'wb')
ReplyDeletegetting msg that undefined variable file, please anyone help me
Nice information thank you,if you want more information please visit our link selenium Online course
ReplyDelete
ReplyDeleteExcellent information,awesome blog
SEO company toronto
SEO agency toronto