# bharathish-diggavi/selenium-testng-framework architecture

> Architecture diagram of the GitHub repository bharathish-diggavi/selenium-testng-framework, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bharathish-diggavi/selenium-testng-framework
- Repository: https://github.com/bharathish-diggavi/selenium-testng-framework

## Overview

##### Main Components
- Test Runner & Build System:
– Represent Maven (pom.xml) and TestNG (testng.xml under the suites folder) as the framework’s entry points.
- WebDriver Management:
– Include the WebDriverContext (in the context package) which manages a single WebDriver instance throughout a test’s lifetime (typically using a singleton or thread-local pattern).
- Page Objects:
– Represent the BasePage and specific page classes (e.g., FacebookLoginPage, GooglePage) located in the pages package.
- Factory:
– Include the PageinstancesFactory from the factory package to show how page objects are created consistently.
- Test Cases:
– Include the BaseTest and concrete test classes (e.g., FaceBookLoginTest, GoogleSearchTest) from the tests package.
- Listeners:
– Show the LogListener and ReportListener from the listeners package that integrate with TestNG to monitor and log events.
- Reporting:
– Represent the ExtentReportManager (and indirectly log utilities, MailUtil, etc.) which generates HTML reports, writes logs (via Log4j), and can even trigger email reports.
- Utilities:
– Group the supporting util classes (LoggerUtil, MailUtil, ReportUtil, TestProperties) that provide functionalities across the framework.
- Configuration:
– Mention configuration files (test.properties, extent-config.xml, log4j.xml) found under src/test/resources/config and src/test/resources for setting up environment variables, report configurations, and log settings.

##### Establish Relationships & Interactions
- The Test Runner (invoked by Maven using the testng.xml suite) kicks off the test execution.
- Test classes (in the tests package) inherit from BaseTest and use WebDriverContext to obtain the WebDriver instance.
- Test classes fetch instances of Page Objects through the PageinstancesFactory, which in turn use the Page classes (BasePage and its subclasses).
- As tests run, Listeners are triggered to log information (via LogListener) and to capture detailed reports (via ReportListener and ExtentReportManager).
- Utility classes (e.g., MailUtil, LoggerUtil) support the framework by handling logging, report generation, and optional email sending of the report.
- The configuration files under resources set up the behavior of various components (e.g., logging details, extent report configurations, and test properties).

##### Architectural Patterns and Design Principles
- Page Object Model (POM):
– Clearly separate page-specific actions and elements into discrete page classes.
- Factory Pattern:
– Use a central PageinstancesFactory to instantiate Page Objects, ensuring consistency.
- Singleton/Thread-local for WebDriver Management:
– WebDriverContext maintains a single instance per test/thread.
- Listener Pattern:
– TestNG listeners (LogListener, ReportListener) are used to hook into test lifecycle events.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build System & Test Runner
    subgraph "Test Runner & Build System"
        TS1["Maven (pom.xml)"]:::testRunner
        TS2["TestNG (suites/testng.xml)"]:::testRunner
    end

    %% Test Cases
    subgraph "Test Cases"
        TC1["BaseTest"]:::testCases
        TC2["FaceBookLoginTest"]:::testCases
        TC3["GoogleSearchTest"]:::testCases
    end

    %% WebDriver Management
    subgraph "WebDriver Manager"
        WD1["WebDriverContext"]:::webDriver
    end

    %% Page Factory & Page Objects
    subgraph "Page Factory & Page Objects"
        PF["PageinstancesFactory"]:::pageFactory
        PO1["BasePage"]:::pageObjects
        PO2["FacebookLoginPage"]:::pageObjects
        PO3["GooglePage"]:::pageObjects
    end

    %% Listeners
    subgraph "Listeners"
        L1["LogListener"]:::listeners
        L2["ReportListener"]:::listeners
    end

    %% Reporting Module
    subgraph "Reporting Module"
        RM["ExtentReportManager"]:::reporting
    end

    %% Utilities
    subgraph "Utilities"
        U1["LoggerUtil"]:::utilities
        U2["MailUtil"]:::utilities
        U3["ReportUtil"]:::utilities
        U4["TestProperties"]:::utilities
    end

    %% Configuration Files
    subgraph "Configuration Files"
        C1["test.properties"]:::config
        C2["extent-config.xml"]:::config
        C3["log4j.xml"]:::config
    end

    %% Relationships
    %% Build System triggers Test Runner
    TS1 -->|"invokes"| TS2
    TS2 -->|"triggers"| TC1
    TS2 -->|"triggers"| TC2
    TS2 -->|"triggers"| TC3

    %% Test Cases interactions
    TC1 -->|"uses"| WD1
    TC2 -->|"uses"| WD1
    TC3 -->|"uses"| WD1

    %% Test Cases using Page Factory to create Page Objects
    TC1 -->|"getsPages"| PF
    TC2 -->|"getsPages"| PF
    TC3 -->|"getsPages"| PF

    PF -->|"creates"| PO1
    PF -->|"creates"| PO2
    PF -->|"creates"| PO3

    %% Test Cases trigger Listeners
    TC1 -->|"notifies"| L1
    TC1 -->|"notifies"| L2
    TC2 -->|"notifies"| L1
    TC2 -->|"notifies"| L2
    TC3 -->|"notifies"| L1
    TC3 -->|"notifies"| L2

    %% Listeners send data to Reporting and Utilities
    L2 -->|"reportsTo"| RM
    L1 -->|"logsTo"| U1
    L2 -->|"logsTo"| U1
    L2 -->|"uses"| U2
    L2 -->|"uses"| U3
    L1 -->|"reads"| U4

    %% Configuration Files support Reporting and Logging
    C3 -->|"configures"| L1
    C3 -->|"configures"| U1
    C2 -->|"configures"| RM
    C1 -->|"providesProps"| U4

    %% Class Definitions for styling
    classDef testRunner fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef testCases fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef webDriver fill:#DA70D6,stroke:#000,stroke-width:2px;
    classDef pageFactory fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef pageObjects fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef listeners fill:#FF7F7F,stroke:#000,stroke-width:2px;
    classDef reporting fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef utilities fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef config fill:#C0C0C0,stroke:#000,stroke-width:2px;

    %% Click Events
    click TS1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/pom.xml"
    click TS2 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/resources/suites/testng.xml"
    click WD1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/context/WebDriverContext.java"
    click PO1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/pages/BasePage.java"
    click PO2 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/pages/FacebookLoginPage.java"
    click PO3 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/pages/GooglePage.java"
    click PF "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/factory/PageinstancesFactory.java"
    click TC1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/tests/BaseTest.java"
    click TC2 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/tests/FaceBookLoginTest.java"
    click TC3 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/tests/GoogleSearchTest.java"
    click L1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/listeners/LogListener.java"
    click L2 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/listeners/ReportListener.java"
    click RM "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/report/ExtentReportManager.java"
    click U1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/util/LoggerUtil.java"
    click U2 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/util/MailUtil.java"
    click U3 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/util/ReportUtil.java"
    click U4 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/java/example/example/util/TestProperties.java"
    click C1 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/resources/config/test.properties"
    click C2 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/resources/config/extent-config.xml"
    click C3 "https://github.com/bharathish-diggavi/selenium-testng-framework/blob/master/src/test/resources/log4j.xml"
```
