How bharathish-diggavi/selenium-testng-framework works
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.