1 / 13

Log4j with selenium tutorial: How to Setup log4j logging in selenium automation framework

In this selenium tutorial, step-by-step process to set up log4j. How to perform & configured log4j with different two ways. Here we will configure log4j manually using a configuration file for our simple script also we can track or debug our script.

Download Presentation

Log4j with selenium tutorial: How to Setup log4j logging in selenium automation framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial Debugging Selenium Scripts with Logs

  2. Introduction • Here, we have included advanced ideas that would benefit from optimizing the Testing Automation framework and produces more clarity to the users. • We would consider the logging feature and it's possible, debugging capabilities etc. • Benefits of Logging in Selenium Scripts:

  3. Log4j Log4j – A Java-based Logging Utility • Let's Discuss the technical aspects of logging. • Log4j was a decision of collaborative endeavors of people at Secure Electronic Marketplace for Europe to produce a utility. • Log4j is an open source tool and licensed under IBM Public License. • It would support us generating logs and hence the log4j came into consideration in the year 1996. • There are three main elements that form the implementation of log4j:

  4. 1. Loggers Logger Class: It is a java based utility/API that has grown all the generic methods already done so that users can enable to use Log4j. • Log Levels: Log levels are commonly identified as to printing methods. These are utilized for printing log messages. • 5 Types of Log Levels: • error() • warn() • info() • debug() • log() • We have to only call any of the above printing methods over the logger instance.

  5. 2. Appenders Now where we can get to view the logs? Answer is "Appenders“ Appenders are generally applied to define the data source/medium where the logs should be created.

  6. 3. Layouts Layouts are a utility that enables the user to choose the wanted set up in which the logs would be performed. Appenders and Layout have a tight coupling between them. Make a note that the user is leveraged to determine various appenders, each map with a different layout.

  7. Installation • Here we learnt about the basics of log4j and its parts, now let's implement these phenomenafor Debugging Selenium Scripts with Logs • Logging using log4j can be performed and configured in particularly two ways: • Using Script via Programmatically • Configuration files via Manually • Above both suggested configuration ways have merit as well as demerits. • Here we will configure log4j manually using Configuration files as its comfort and simplicity.

  8. Continue To create a log4j.xml file. You can use below code in configuration file:

  9. Continue • The output of the above code is: • 01-07-2014 12:56:32 INFO [GmailLogin]: Sample log message • Here, • First is Execution Date • Second is Time in which the test step was performed • Third is one of the log level • Fourth is name of the test class • Fifth is Log message • Put the log4j.XML file into the project’s root folder/base directory now.

  10. Continue Now parse the log4j.xml file

  11. Continue Now we have to generate a test class “GmailLogin.java” under the project. Then import the logger class to be able to perform the log statements. Syntax: import org.apache.log4j.Logger; Now instantiate the object of the Logger class Syntax: //object initialization for log static Logger log = Logger.getLogger(Demo.class.getName()); This logger will be used over the complete test class to create the log statements.

  12. Conclusion Here we used log4j use to perform logging. We explained the essential parts that form log4j from a usability view. With the Appenders and layouts, you can leverage to determine the wanted logging form/model and the data reference/position. References: Debugging Selenium Scripts with Logs (Log4j Tutorial) Debugging Selenium Scripts with Logs

  13. Contact Us Web: www.nexsoftsys.com Email: info@nexsoftsys.com Call: +1-646-971-0799

More Related