Sunday, February 23, 2020

Generate simple HTML report for your test/automation scripts in Python

automation-report  is PyPI package that generates the HTML report for your Python automation script with valid status of overall test case and its steps.

Installation:

pip install automation-report

Sample Code: 

Importing package
from automation_report.report import AutomationReport

Passing optional 'options' dictionary as parament with following keys
  • LogoImage : Provide URL of the image 
  • MainHeader: When header text is to be used instead of logo 
  • FooterContent: Provide HTML content to add on the footer section
options = {}
#options["LogoImage"] = "logo.png"
options["MainHeader"] = "Automation Report"
options["FooterContent"] = "<a href='#'>Link</a>" 

Create new object for your first test with Report name and optional "options" dictionary
new_report = AutomationReport("Login Test", options)

Use starttest() method to start a new case with its name given as parameter
new_report.starttest("CASE 0001: Login to the system")

Populate the various steps status with info(), success(), fail() methods for particular case
new_report.info("Entered email in email field")
new_report.success("Login Successfully:")

End above started case
new_report.endtest()

Create yet another case as following
new_report.starttest("CASE 0002: Logout User")
new_report.info("User is logged in")
new_report.success("Logout link is present")
new_report.fail("User not logged out")
new_report.endtest()

Use close method to finally complete the whole report generation
new_report.close()

Screenshots: 






Find the source code: Github
Read more

Saturday, February 22, 2020

Python Decorators : Simple Python program with decorators

Decorator functions help to add new functionality to existing function without modifying the structure of existing one.
# Defining decorator function welcome_to_school

def welcome_to_school(func):

    def welcome_message_school(*args):

        print("\n##################### Welcome to School #####################")

        func(*args) 

    return welcome_message_school;

    

@welcome_to_school

def welcome_message_chemistry(name):

    print("Welcome to Chemistry class," , name)


@welcome_to_school

def welcome_message_biology(name):

    print("Welcome to Biology class," , name)

    

welcome_message_chemistry("Chemistry Boy")

welcome_message_biology("Biology Girl")


Output:

Read more

Wednesday, July 27, 2016

Search Input box with search icon attached ( HTML,CSS ,bootstrap )

Want to have search input box along with the bootstrap search icon attached to it for any webpage , blogger? Use the following code to get that.

HTML code to get the HTML input box and search icon

<form action="/search" class="navbar-form search-form" id="searchform" method="get" role="search">
<div class="add-on input-group">
<input class="search-field form-control" id="search" name="q" placeholder="Search this blog.." type="search" value="" />
    <br />
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
    </div>
</div>
</form>

CSS Code
.add-on{
 width:230px;
 margin-top:10px;
}
.add-on .input-group-btn > .btn {
   border-left-width:0;left:2px;
   -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
 height:42px;
}

Read more