Latest post from this blog

Test Scenarios vs. Test Cases: Understanding the Basics

What Are Test Scenarios Test scenarios represent high-level ideas or conditions that need to be validated to ensure the application works as expected. They provide a broader perspective and are typically used during the test planning phase. Purpose: To capture the "what to test" without going into granular details. Example of a Test Scenario: Verify that a user can successfully log in to the application using valid credentials. Verify the behavior of the login page when invalid credentials are entered. Verify the application behavior when the login button is clicked without entering any credentials. What Are Test Cases Test cases are detailed documents that define the specific steps to execute a test. They cover inputs, execution steps, expected results, and actual outcomes. Purpose: To guide the tester step-by-step on "how to test." Example of a Test Case (for the first scenario): Test Case ID TC_01_Login_Valid_Credentials Test Scenario Verify user login with val...

How to Maintain Logs in Your Automation Framework

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.
Setting Up a Logging Framework
  1. Choosing a Library: Explain why you chose a specific logging library (e.g., Log4j2).
  2. 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>

      3. Configuration:
  • 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.
Analyzing and Managing Logs:
  • 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.
Conclusion:
Summarize the benefits of maintaining logs in an automation framework.
Encourage adopting good logging practices to improve debugging and maintainability.

Comments

Popular posts from this blog

Common Exception in Selenium

Test Scenarios vs. Test Cases: Understanding the Basics

Handling Shadow DOM in Selenium WebDriver

Handling HTTPS Websites and SSL Certificate Errors in Selenium

Normalize-space Function In Xpath