Debugging Selenium Scripts with Logs

The current tutorial, we would motion towards some advanced concepts. Those help in optimizing the Automation framework and visibility to the users in Selenium  Training Institute Hyderabad. The logging feature, its potential, debugging capabilities and much more. Sometimes logging considered being an overhead upon the existing script creation mechanism.

Advantages of Logging 

Logs review to find out the application’s health by the stakeholders

Log4j – a Java based Logging API

 The technical details about logging discuss the origin of the API. That we would be using throughout the log4j tutorial to generate logs. It is a result of collaborative efforts of people at Secure Electronic Marketplace in Selenium. To develop a utility that would help us generating logs. The log4j came into limelight in the year 1996. It is an open source tool and licensed under IBM Public License. There are three main components constituents of log4j. These components represent the details the log level, formats of the log message in Selenium.

Constituents of Log4j

   1.  Loggers   2.   Appenders   3.   Layouts

#1) Loggers

The steps need to done to install loggers in the project.  1. Creating an instance of Logger class.  2. Defining the log level.

Logger Class:

It is a java based utility. That has got all the generic methods already implemented so those unable to use log4j in Selenium.

Log levels:

Log levels are known as printing methods. These uses for printing the log messages. There are five kinds of log levels.   error()   warn()   info()   debug()   log() Thus to be able to generate logs, all we need to do is to call any of the printing methods over the logger instance. We will have a broader look into it during the implementation phase.

#2) Appenders

That generate logs next thing that should pop up into our minds. The Appenders use to specify the data source/medium where the logs generate. The scope of data sources stretches from various external mediums. Like console, GUI, text files in selenium.

#3) Layouts

At times, the user wishes certain information append with each log statement. For example, I wish to a print a timestamp along with my log statement. Thus, such requirements accomplished by Layouts in Selenium. Layouts are a utility that allows the user to opt for the desired format in which the logs render. The Appenders and Layout have a tight coupling between them. Thus, we need to map each of the appenders with a specific layout. Take a note that user leverage to define many appenders, each mapped with a distinct layout.