htmllogger
Python library provides customized Test Report for selenium or any other automation framework
Introduction.
Main Features:
- Create an interactive html report for automation suite.
- It can be easily integrated with unit testing frameworks eg. unittest,pytest
- It provides three methods inorder to generate report for tests.
- It combines execution result of all tests which are executed in batch.
Installation
pip install:
> pip install htmllogger
Pre-Requisite
- You will have to initialise htmllogger object to start use of reporting functions.
- At the start of each test you have to use 'assert_testcase_log("Test_Case_name")',
- Inorder to detailing of testcase steps you will have to use 'assert_step_log('Test_step_details')'
- To handle failures you will write your test in 'Try Except' block and in except block call
'assert_step_fail_log(driver, str(e))' pass First argument as driver object to capture screenshot of failure.
second argument is except object converted in string format.
Follow below examples for more understanding...
Examples
- Python - Unittest
import unittest
from selenium import webdriver
from htmllogger.Htmllogger import HTMlLogger
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
class InputFormsCheck2(unittest.TestCase):
def setUp(self):
self.logger = HTMlLogger('Path of folder where we need to create report')
binary = FirefoxBinary('Binary Path for your browser')
self.driver = webdriver.Firefox(firefox_binary=binary,
executable_path=r"/geckodriver.exe")
def test_singleInputField(self):
self.logger.assert_testcase_log("Test Single Input Field")
try:
pageUrl = "http://www.seleniumeasy.com/test/basic-first-form-demo.html"
driver = self.driver
driver.maximize_window()
driver.get(pageUrl)
eleUserMessage = driver.find_element_by_id("user-message")
eleUserMessage.clear()
eleUserMessage.send_keys("Test Python")
self.logger.assert_step_log("Entered text [Test Python] in [user-message] EditBox.")
eleShowMsgBtn = driver.find_element_by_css_selector('#get-input > .btn')
eleShowMsgBtn.click()
self.logger.assert_step_log("Clicked on [Show Message] Button.")
eleYourMsg = driver.find_element_by_id("display")
assert "Test Python" in eleYourMsg.text
except Exception as e:
self.logger.assert_step_fail_log(driver, str(e))
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
- Python - Pytest
Inside test_Login.py
import pytest
from selenium import webdriver
from htmllogger.Htmllogger import HTMlLogger
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
@pytest.fixture()
def setup(request):
print("initiating driver")
logger = HTMlLogger('Path of folder where we need to create report')
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary,executable_path=r"D:/SeleniumTest/SeleniumTest/MainResources/drivers/geckodriver.exe")
request.instance.driver = driver
request.instance.logger = logger
driver.get("http://seleniumeasy.com/test")
driver.maximize_window()
yield driver
driver.close()
@pytest.mark.usefixtures("setup")
class TestExample:
def test_title(self):
try:
self.logger.assert_testcase_log("Testcase :Testing Title")
print("Verify title...")
assert "Selenium Easy" in self.driver.title
self.logger.assert_step_log("Successfully verified title")
except Exception as e:
self.logger.assert_step_fail_log(self.driver, str(e))
def test_content_text(self):
self.logger.assert_testcase_log("Testcase : Testing Content")
try:
print("Verify content on the page...")
centerText = self.driver.find_element_by_css_selector('.tab-content .text-center').text
self.logger.assert_step_log("Verify content on page")
assert "WELCOME TO SELENIUM EASY DEMO" == centerText
except Exception as e:
self.logger.assert_step_fail_log(self.driver, str(e))