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 −
This will log nothing.
This will provide exhaustive information which is essential for debugging the code in case of errors.
This will provide information in case there are no errors encountered and test execution running smoothly.
This will provide information in case there is a possibility of errors or some unexpected events that are imminent.
This will provide information in case there are severe errors and there are major deviations from the expected behavior of our application.
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.
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')