Industrial standard automation framework were api and ui both are there

 




Folder Structure (only UI)

Explanation of Components
Base Class (BaseClass.java):

This is the parent class for all test classes.

Contains common methods like WebDriver initialization, browser setup, and cleanup.

Handles TestNG annotations like @BeforeSuite, @BeforeTest, @AfterTest, etc.

Pages (com.projectname.pages):

Follows the Page Object Model (POM) design pattern.

Each page (e.g., LoginPage.java, HomePage.java) contains locators and methods specific to that page.

Promotes reusability and maintainability.

Utils (com.projectname.utils):

Contains utility classes for common functionalities:

ExcelUtils.java: Reads/writes data from/to Excel files (e.g., TestData.xlsx).

PropertiesUtils.java: Reads configuration data from config.properties.

Other utility classes for reusable methods like waits, screenshots, etc.

Listeners (com.projectname.listeners):

TestNGListener.java: Implements TestNG listeners like ITestListener and ISuiteListener.

Used to customize TestNG behavior (e.g., logging, reporting, retry failed tests).

Reports (com.projectname.reports):

ExtentReportManager.java: Configures and manages Extent Reports.

Generates detailed HTML reports with test case status, logs, and screenshots.

Config (com.projectname.config):

log4j2.xml: Configuration file for Log4j2 logging.

extent-config.xml: Configuration file for Extent Reports.

Constants (com.projectname.constants):

Constants.java: Stores constant values like file paths, URLs, and other static data.

Test Scripts (com.projectname.tests):

Contains TestNG test classes (e.g., LoginTest.java, HomeTest.java).

Each test class corresponds to a specific functionality or module.

Test cases are annotated with @Test and include a unique testCaseId.

Test Data (com.projectname.testdata):

TestData.xlsx: Excel file to store test data (e.g., usernames, passwords, input values).

Data-driven testing is achieved by reading data from this file.

Resources (src/test/resources):

config.properties: Stores configuration data like browser type, URL, and environment-specific settings.

log4j2.xml: Log4j2 configuration file for logging.

Test Output (test-output):

ExtentReports: Contains generated Extent Reports in HTML format.

Logs: Stores application logs generated by Log4j2.

POM (pom.xml):

Maven configuration file to manage dependencies (e.g., Selenium, TestNG, Log4j2, Extent Reports).

Key Components and Their Usage
Log4j2:

Used for logging test execution details (e.g., info, debug, error).

Configuration is done via log4j2.xml.

Logs are stored in the test-output/Logs folder.

TestNG Listeners:

Custom listeners are used to enhance TestNG functionality.

Examples: Logging test status, retrying failed tests, and capturing screenshots on failure.

Extent Reports:

Generates detailed and interactive HTML reports.

Includes test case status, execution time, logs, and screenshots.

Configured using extent-config.xml.

Data Reading from Excel:

ExcelUtils.java reads test data from TestData.xlsx.

Supports data-driven testing by providing input data for multiple test cases.

Properties File:

config.properties stores environment-specific configurations (e.g., browser, URL).

PropertiesUtils.java reads these configurations at runtime.

Base Class:

Centralizes common functionalities like WebDriver setup and teardown.

Ensures consistency across all test classes.

Page Object Model (POM):

Separates test logic from page-specific logic.

Improves code readability and maintainability.

Test Scripts:

Each test script corresponds to a specific test case.

Test cases are annotated with @Test and include a unique testCaseId for traceability.

Workflow
Initialization:

The BaseClass initializes the WebDriver and reads configurations from config.properties.

Log4j2 starts logging test execution details.

Test Execution:

Test scripts (LoginTest.java, HomeTest.java) execute using data from TestData.xlsx.

TestNG listeners monitor test execution and log results.

Reporting:

Extent Reports generate detailed HTML reports in the test-output/ExtentReports folder.

Logs are stored in the test-output/Logs folder.

Cleanup:

The BaseClass closes the browser and cleans up resources after test execution.

Folder Structure (only UI and API)

Explanation of New/Updated Components
Base Classes:

BaseTest.java: Common base class for both UI and API tests. Contains shared utilities and configurations.

WebBaseTest.java: Extends BaseTest for UI-specific setup (e.g., WebDriver initialization).

ApiBaseTest.java: Extends BaseTest for API-specific setup (e.g., RestAssured configuration).

API Section (com.projectname.api):

endpoints: Contains classes for API endpoints (e.g., UserEndpoints.java, ProductEndpoints.java).

models: Contains POJOs (Plain Old Java Objects) for API request/response payloads (e.g., User.java, Product.java).

utils: Contains utility methods for API testing (e.g., ApiUtils.java for common API operations).

Test Data:

TestData.xlsx: Excel file for UI test data.

ApiTestData.json: JSON file for API test data (e.g., request payloads, expected responses).

API Configuration:

api-endpoints.properties: Stores API endpoint URLs for different environments.

Test Scripts:

UI Tests: Located in com.projectname.tests.ui (e.g., LoginTest.java, HomeTest.java).

API Tests: Located in com.projectname.tests.api (e.g., UserApiTest.java, ProductApiTest.java).

Jenkins Pipeline:

Jenkinsfile: Defines the CI/CD pipeline for running UI and API tests.

Can be configured to run tests in parallel, generate reports, and send notifications.

Workflow for UI and API Automation
Initialization:

UI Tests: WebBaseTest initializes the WebDriver and sets up the browser.

API Tests: ApiBaseTest configures RestAssured (e.g., base URI, authentication).

Test Execution:

UI Tests: Test scripts interact with web pages using Selenium and validate UI elements.

API Tests: Test scripts send HTTP requests using RestAssured and validate responses.

Reporting:

Extent Reports generate a unified report for both UI and API tests.

Logs are stored in the test-output/Logs folder.

Cleanup:

UI Tests: Close the browser and clean up resources.

API Tests: No cleanup required for API tests.

Jenkins Pipeline Integration
Jenkinsfile:

Defines stages for building, testing, and reporting.

Example stages:

Pipeline Execution:

Jenkins pulls the code from the repository.

Runs UI and API tests in parallel or sequentially.

Generates and archives test reports.

Sends email notifications with test results.

Benefits of This Framework
Unified Framework:

Combines UI and API automation in a single project.

Promotes reusability of common utilities and configurations.

Scalability:

Easy to add new UI or API test cases.

Supports data-driven testing for both UI and API.

CI/CD Integration:

Jenkins pipeline automates test execution and reporting.

Ensures continuous testing and feedback.

Detailed Reporting:

Extent Reports provide a unified view of UI and API test results.

Logs and screenshots help in debugging.


Purpose of Different Logging & Reporting Components



Next Post Previous Post
No Comment
Add Comment
comment url