What is the importance of logging in Selenium with python?

Selenium Web DriverAutomation TestingSoftware Testing

While building our test cases in Selenium, we need to implement a logging feature in our framework. It is essential for monitoring the flow of the program and then include other edge scenarios which we might have missed.

The logs can give more information whenever there are errors than stack trace by logging the prior test step execution status and details. Thus debugging becomes easy and quick. Most logs are maintained in separate files which can be shared with other non- technical team members for analyzing a root cause for a failure.

There are six logging levels with each level assigned an integer for determining the severity of the log. They are listed below −

  • NOTESET=0

This will log nothing.

  • DEBUG=10

This will provide exhaustive information which is essential for debugging the code in case of errors.

  • INFO=20

This will provide information in case there are no errors encountered and test execution running smoothly.

  • WARN=30

This will provide information in case there is a possibility of errors or some unexpected events that are imminent.

  • ERROR=40

This will provide information in case there are severe errors and there are major deviations from the expected behavior of our application.

  • CRITICAL=50

This will provide information in case there are more severe errors and the execution has terminated all together.

To add logging to our test case, first we have to import the logging package. Then we access the corresponding methods of the logging.

Example

Coding Implementation of logging.

import logging
# to get debug log
logging.debug('This is a debugging log with severity 10')
# to get information log
logging.info('This is an information log with severity 20')
# to get warning log
logging.warning('This is a warning log with severity 30')
# to get error log
logging.error('This is an error log with severity 40')
# to get critical log
logging.critical('This is a critical log with severity 50')
raja
Published on 29-Jul-2020 14:25:40
Advertisements