Python Selenium : HtmlTestRunner and Screenshot feature.
Introduction
HtmlTest runner
HtmlTest runner is a unittest test runner that save test results in Html files, for human readable presentation of results.Screenshots
In automation, it is mandatory to take the screenshot for verification so that can prove also that your test case has covered certain functionality or not. Screenshots help you a lot when your test case will fail so that you can identify what went wrong in your script or in your application.1. HtmlTestRunner Installation
You can install and read more about HtmlTestRunner from the Github..HtmlTestRunner Github Page
Using pip, you can install selenium like this:
pip install html-testRunner
2. Sample Selenium Test
create pythonorg-sample.py
import unittest
import HtmlTestRunner
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
# take screen shot
self.driver.save_screenshot("python-org.png")
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
# take screen shot after search
self.driver.save_screenshot("python-org-after-search.png")
assert "No results found." not in driver.page_source
def test_error(self):
""" This test should be marked as error one. """
raise ValueError
def test_fail(self):
""" This test should fail. """
self.assertEqual(1, 2)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='report'))
3. Run Selenium Test
python pythonorg-sample.py
4. Screenshots
HtmlTestRunner
Console Log
Running tests...
----------------------------------------------------------------------
This test should be marked as error one. ... ERROR (1.961452)s
This test should fail. ... FAIL (1.838222)s
test_search_in_python_org (__main__.PythonOrgSearch) ... OK (12.246906)s
======================================================================
ERROR [1.961452s]: This test should be marked as error one.
----------------------------------------------------------------------
Traceback (most recent call last):
File "pythonorg-sample.py", line 31, in test_error
raise ValueError
ValueError
======================================================================
FAIL [1.838222s]: This test should fail.
----------------------------------------------------------------------
Traceback (most recent call last):
File "pythonorg-sample.py", line 35, in test_fail
self.assertEqual(1, 2)
AssertionError: 1 != 2
----------------------------------------------------------------------
Ran 3 tests in 0:00:16
FAILED
(Failures=1, Errors=1)
Generating HTML reports...
Looks great and every freshers want to go through your blog for their growth.
ReplyDeleteSelenium Training in Bangalore
Selenium Training Institutes in Bangalore
Selenium Classes in Bangalore
Selenium Training in Coimbatore
Selenium Course in Coimbatore
Selenium Classes in Coimbatore
Nice content! It was very useful for my development. Thank you for your great post and I like more one post from your blog...
ReplyDeleteSpark Training in Chennai
Spark Training Fees in Chennai
Pega Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Linux Training in Chennai
Social Media Marketing Courses in Chennai
Power BI Training in Chennai
Tableau Training in Chennai
I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
ReplyDeleteRegards,
PHP Training in Chennai
PHP Course in Chennai
Tally Course in Chennai
ReactJS Training in Chennai
microsoft dynamics crm training in chennai
PHP Training in Chennai
PHP Course in Chennai
Thank you so much for providing information on this. It was very useful.
ReplyDeleteGuest posting sites
Technology
Nice blog. Can't be written much better. You’re doing a great job. Keep continuing.
ReplyDeleteAngular JS Training in Chennai
Uipath Training in Chennai
Great blog thanks for sharing Searching for a SEO company in Chennai that can bring your brand to the top results page on Google? Look no further - Adhuntt Media, with their team of SEO experts, can make it happen that too for the best value.
ReplyDeletedigital marketing company in chennai
seo service in chennai
web designing company in chennai
social media marketing company in chennai
Nice blog thanks for sharing Let’s be practical this special day and rent plants at the best price. Karuna Nursery Gardens offers amazing plant rental services in Chennai. Exquisite deals and truckloads of variety to aim to please even the most niche of tastes in our customers.
ReplyDeleteplant nursery in chennai
rental plants in chennai
corporate gardening service in chennai
Excellent blog thanks for sharing Pixies beauty Shop is the best place to buy cosmetics in Chennai. With thousands of premium imported brands to choose from, you’ll never run out of lipstick again. And don’t forget about the best offers and value they provide.
ReplyDeleteCosmetics Shop in Chennai