Latest post from this blog
How to Maintain Logs in Your Automation Framework
- Get link
- X
- Other Apps
Introduction
- Importance of logs in debugging and maintaining automation frameworks.
- Types of logs (Execution logs, Application logs, Error logs).
- Overview of popular logging libraries such as Log4j, SLF4J, or java.util.logging.
- Choosing a Library: Explain why you chose a specific logging library (e.g., Log4j2).
- Adding Dependencies: Show how to add the library to your project using Maven/Grad
XML
<!-- Example for Log4j2 --><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.x.x</version></dependency>
- Provide a sample configuration file (log4j2.xml or logback.xml).
- Discuss different log levels (INFO, DEBUG, WARN, ERROR).
XML
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss} %-5p %c{1} - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Con
figuration>
Integrating Logs in Your Framework
1. Creating a Utility Class:
Create a Logger utility for centralized logging.
Java Code:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LogUtil {
private static final Logger logger = LogManager.getLogger(LogUtil.class);
public static void info(String message) {
logger.info(message);
}
public static void error(String message, Throwable t) {
logger.error(message, t);
}
}
2. Adding Logs in Tests:
Show how to use the logger in your test cases and Page Object methods.
Example:
LogUtil.info("Navigating to login page");
driver.get("https://example.com/login");
3.Logging Across Framework Layers:
- Logs for driver initialization, framework setup, and teardown.
- Logs for actions in test cases and validation steps.
- Storing Logs: Save logs in a central location for CI/CD pipelines.
- Third-party Tools: Discuss tools like ELK Stack, Splunk, or Datadog for advanced log analysis.
Comments
Post a Comment