Thursday, August 2, 2018

Python Selenium : Generating the HTML Test Report and Screenshot feature.

Python Selenium : HtmlTestRunner and Screenshot feature.


HtmlTest runner
HtmlTest runner is a unittest test runner that save test results in Html files, for human readable presentation of results.

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


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

        # take screen shot

        elem = driver.find_element_by_name("q")

        # take screen shot after search

        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):

if __name__ == "__main__":

3. Run Selenium Test


4. Screenshots

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 "", line 31, in test_error
    raise ValueError

FAIL [1.838222s]: This test should fail.
Traceback (most recent call last):
  File "", line 35, in test_fail
    self.assertEqual(1, 2)
AssertionError: 1 != 2

Ran 3 tests in 0:00:16

 (Failures=1, Errors=1)

Generating HTML reports...

Location: Mumbai, Maharashtra, India


  1. Thank you so much for providing information on this. It was very useful.

    Guest posting sites

  2. Nice blog. Can't be written much better. You’re doing a great job. Keep continuing.

    Angular JS Training in Chennai
    Uipath Training in Chennai

  3. 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.
    digital marketing company in chennai
    seo service in chennai
    web designing company in chennai
    social media marketing company in chennai

  4. 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.
    plant nursery in chennai
    rental plants in chennai
    corporate gardening service in chennai

  5. 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.
    Cosmetics Shop in Chennai


  6. This content of information has
    helped me a lot. It is very well explained and easy to understand.

    Tally Course


  7. You write this post very carefully I think, which is easily understand to me. Not only this, other post is also good. As a newbie this info is really helpful for me. Thanks to you.

    SEO Training

  8. Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.

  9. 7 tips to start a career in digital marketing

    “Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.

    we have offered to the advanced syllabus course digital marketing for available join now

    more details click the link now


  10. Web designing trends in 2020

    When we look into the trends, everything which is ruling today’s world was once a start up and slowly begun getting into. But Now they have literally transformed our lives on a tremendous note. To name a few, Facebook, WhatsApp, Twitter can be a promising proof for such a transformation and have a true impact on the digital world.

    we have offered to the advanced syllabus course web design and development for available join no

    more details click the link now



  11. Thanks for your extraordinary blog. Your idea for this was so brilliant. This would provide people with an excellent tally resource from someone who has experienced such issues. You would be coming at the subject from a different angle and people would appreciate your honesty and frankness. Good luck for your next blog!
    Tally ERP 9 Training
    tally classes
    Tally Training institute in Chennai
    Tally course in Chennai
    seo training classes
    seo training course
    seo training institute in chennai
    seo training institutes
    seo courses in chennai
    seo institutes in chennai
    seo classes in chennai
    seo training center in chennai