Reporting & Logging

 

Log4j Setup

Learning Outcome

4

Integrate Log4j with Selenium tests

3

Use log levels (INFO, DEBUG, ERROR, WARN)

2

Configure Log4j in framework using properties/XML file

1

Understand purpose of Log4j in automation

5

Improve debugging and tracking of test execution

Recall

Basic Java programming (classes, objects, methods)

File handling in Java (reading configuration files)

Exception handling in Java and Selenium WebDriver basics (test execution flow)

Test automation framework structure (POM, TestNG/JUnit)

Configuration management (properties files, JSON)

Basic understanding of debugging and logging concepts

To learn Log4j Setup, revise the below concepts.

Think of an automation framework like running a hotel:

 

Utilities = Hotel Staff Tools

Utilities are like helpers used by staff for repeated tasks:

 

Housekeeping tools → cleaning rooms (like reusable functions)

Reception desk support → check-in/check-out handling

Billing calculator → payment calculations

Staff don’t create new tools every time—they reuse the same ones.
Similarly, utilities are common reusable methods used across tests.

Config Management = Hotel Settings Book

 

Configuration files are like a hotel rule/settings book:

 

Instead of changing everything manually, staff just refer to the book.

  • Room prices (test data)

  • Wi-Fi settings (URLs)

  • Staff rules for different branches (QA, UAT, Prod environments)

Similarly, config files store environment-specific settings outside the code.

 

  • Utilities = reusable helpers (tools)

  • Config = centralized settings (rule book)

Why is Log4j used?

 

Log4j is used to record events during application or test execution

It helps in debugging by tracking step-by-step execution flow

It provides different log levels (INFO, DEBUG, WARN, ERROR) to control logging detail

It helps identify errors and failures quickly in automation scripts

It creates structured and readable logs instead of using print statements

It improves monitoring and maintenance of automation frameworks

It supports generating log files for future analysis and reporting framework

 What is Log4j ?

  

Log4j (short for Apache Logging Services for Java) is a widely used logging framework developed by the Apache Software Foundation.

 It helps Java applications record information about what they’re doing—especially useful for debugging, monitoring, and auditing.

 

Example

A Java developer might use Log4j to record:

 

  • When a user logs in

  • When an error occurs

  • Performance metrics (like response time)

Utilities in Project Setup (utils package)

 

Location:  src/test/java/utils

 Purpose:
           
To store reusable common functions used across the framework.

 

 Common Utility Classes:

 

✔️WebDriverUtility

  • Browser setup & teardown

  • Window maximize

  • Implicit/explicit waits

✔️ ScreenshotUtility

  • Capture screenshots on failure

  • Save in reports folder

What is Configuration Management?

 

Configuration Management is the process of storing and managing environment settings and test data externally instead of hardcoding them in scripts.

 

Examples:

 

  • URL of application

  • Browser type

  • Username/password

  • Environment details (QA, UAT, Prod)

Usually stored in files like:

 

  • config.properties

  • JSON

  • YAML

 Purpose:
           To make the framework flexible and easy to maintain.

 

Configuration Management Project Setup

 

Location:

 

src/main/resources/config.properties

 

Example config.properties:

 

 

browser=chrome

url=https://example.com

username=admin

password=admin123

timeout=10

 

Purpose:

        Stores environment and application settings outside code

 

Config Reader Utility

 

Example:

 

public class ConfigReader 
{
 Properties prop;
public ConfigReader() {
       FileInputStream fis = new FileInputStream("config.properties");
       prop = new Properties();
       prop.load(fis);
   }
   public String getBrowser() {
       return prop.getProperty("browser");
   }
   public String getUrl() {
       return prop.getProperty("url");
   }
}

Config Reader Utility

 

Usage in Test:

 

ConfigReader config = new ConfigReader();
driver.get(config.getUrl());

 Benefits:

 

 

  • No hardcoding in scripts

  • Easy environment switching (QA/UAT/Prod)

  • Centralized configuration control

  • Flexible framework

AutomationFramework/

 

 

├── src/test/java

│   ├── tests/

│   ├── pages/

│   └── utils/

├── src/main/resources

│   ├── config.properties

│   ├── testdata.json

├── drivers/

├── reports/

└── pom.xml


 

 Real Project Flow

 

 

Step 1:

Read config → browser + URL

 

Step 2 :

Launch browser using WebDriverUtility

 

Step 3:

Execute test using Page Objects

 

Use utilities for waits, screenshots, etc.

 

Step 5:

Generate reports

 

Step 4 :

Summary

4

3

2

1

WebElements represent HTML elements on a web page in Selenium.

5

Check element states: displayed, enabled, selected.

 

Perform actions: click, type, clear, submit.

1

Utilities provide reusable functions for common automation tasks.

2

They handle actions like waits, screenshots, and browser setup efficiently.

3

Test data and configuration are managed separately from test scripts.

4

Configuration files (properties/JSON) improve flexibility of the framework.

This approach reduces duplication and enhances reusability, maintainability, and scalability.

Quiz

What is stored in Configuration Management files?

A. Only test scripts

B. UI locators only

C. Environment settings like URL and browser

D. Only test reports

 

Quiz - Answer

What is stored in Configuration Management files?

A. Only test scripts

B. UI locators only

D. Only test reports

 

C. Environment settings like URL and browser