https://github.com/akashgkrishna/bookcart
A Selenium-based test automation framework for the BookCart web application
https://github.com/akashgkrishna/bookcart
allure-report java selenium testng-framework
Last synced: about 2 months ago
JSON representation
A Selenium-based test automation framework for the BookCart web application
- Host: GitHub
- URL: https://github.com/akashgkrishna/bookcart
- Owner: akashgkrishna
- License: mit
- Created: 2025-01-26T08:44:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-01T08:12:54.000Z (over 1 year ago)
- Last Synced: 2025-04-05T22:29:35.975Z (about 1 year ago)
- Topics: allure-report, java, selenium, testng-framework
- Language: Java
- Homepage: https://bookcart.azurewebsites.net/
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BookCart Test Automation Framework
[](https://www.java.com/) [](https://www.selenium.dev/) [](https://testng.org/) [](https://logback.qos.ch/) [](https://docs.qameta.io/allure/) [](https://projectlombok.org/)
A Selenium-based, cross-browser test automation framework for the BookCart web application, supporting multiple environments, data-driven testing, reporting with Allure and custom logging.
## Table of Contents
- [Features](#features)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Execution](#execution)
- [Logging](#logging)
- [Project Structure](#project-structure)
- [Best Practices](#best-practices)
- [Future Roadmap](#future-roadmap)
- [License](#license)
## Features
- **Environment Config**: Easily switch between QA, Staging, and Production via `config.properties` and system properties.
- **Driver Management**: Centralized driver handling.
- **Page Object Model (POM)**: Structured POM with separate packages for base pages, common components, and specialized pages.
- **Test Flow Abstraction**: Business logic encapsulated in flow classes (e.g., `LoginFlow`, `UserRegistrationFlow`).
- **Data-Driven Testing**: Centralized data generation with TestNG data providers for unique test runs.
- **Allure Reporting**: Auto-attached step annotations, failure screenshots, test descriptions, severity levels, and TMS links.
- **Custom Logging**: SLF4J/Logback with custom logger for clear, secure logs.
- **Lombok Integration**: Clean models with `@Builder`.
- **AspectJ Weaving**: Runtime instrumentation for enhanced reporting.
- **Smart Waits**: Mix of explicit waits and utility methods.
- **Headless Execution**: Configurable via `config.properties`.
## Prerequisites
- **Java 22 JDK**
- **Maven 3.6+**
- **Chrome Browser (latest)**
- **IDE** (IntelliJ/Eclipse/VSCode)
## Installation
1. Clone the repository:
`git clone git@github.com:akashgkrishna/BookCart.git `
2. Build the project:
`mvn clean install`
## Configuration
### Environment Setup: (`config.properties`)
- Edit `src/main/resources/config.properties` to modify environment URLs
- Supported environments: QA, Prod, Staging
- Default environment: QA
```properties
# Environment URLs
qa.url=https://bookcart.azurewebsites.net/
staging.url=https://staging-bookcart.azurewebsites.net/
prod.url=https://prod-bookcart.azurewebsites.net/
# Credentials
qa.username=qa_user
qa.password=qa_password
staging.username=staging_user
staging.password=staging_password
prod.username=prod_user
prod.password=prod_password
```
### Log Configuration: (`logback.xml`)
```xml
```
### Browser setup:
- Currently, supports (Chrome, Firefox, Safari and Edge)
- Chrome is the default browser .
- If you want other drivers just add the appropriate WebDriver instance in DriverManager class
```properties
# Browser configuration
browser=chrome
headless=true
```
### Safari Browser setup:
Safari's settings need to be adjusted to allow automation.
Follow these steps:
1. **Enable the Develop Menu:**
Open Safari and go to **Safari > Preferences > Advanced**. Then, check the box that says **"Show Develop menu in menu bar"**.
2. **Allow Remote Automation:**
Once the Develop menu is visible, click on **Develop** in the menu bar and select **"Allow Remote Automation"**. This setting permits WebDriver to control Safari.
3. **Restart Safari:**
After enabling the setting, close Safari and re-launch it to ensure the changes take effect.
These adjustments should allow SafariDriver to create a new session successfully.
### Lombok setup
Verify Lombok is enabled in your IDE. Without Lombok processing, none of the builder methods or getters (provided by `@Getter` and `@Builder`) are generated.
**1. Add Lombok Dependency:**
Ensure that your `pom.xml` contains the Lombok dependency. For example:
```xml
org.projectlombok
lombok
1.18.24
provided
```
**2. Enable Annotation Processing:**
- If you’re using an IDE like IntelliJ IDEA or Eclipse, make sure that annotation processing is enabled.
- For Maven, the compiler plugin should pick up Lombok annotations if the dependency is correctly added.
**3. Clean and Rebuild:**
After adjusting your configuration, perform a clean build (e.g., `mvn clean compile`) to verify that Lombok generates the expected methods.
### Allure Configuration (`allure.properties`)
```properties
allure.results.directory=target/allure-results
```
### Error Messages (`error-messages.properties`)
```properties
invalid.username=User Name is not available
invalid.password=Password requirements not met
```
### TestNG Suite (`testng.xml`)
```xml
```
## Execution
### Default (QA Environment):
```bash
mvn test
```
### Specific Environment:
```bash
mvn test -Denv=prod
```
### Supported Environments:
- `-Denv=qa` (default)
- `-Denv=staging`
- `-Denv=prod`
### Generate Allure Report
```bash
mvn allure:serve
```
## Logging
### Usage in Tests:
```java
public class BasicTest extends BaseTest {
@Test
public void exampleTest() {
logger.info("Using credentials: {}", username);
logger.error("Validation failed!");
}
}
```
### Log Outputs:
```
14:23:45 INFO [TestNG] o.b.BasicTest - Using credentials: test01
14:23:46 ERROR [TestNG] o.b.BasicTest - Validation failed!
```
## Project Structure
```
├── LICENSE // License information (e.g., MIT License)
├── README.md // Project documentation and usage instructions
├── pom.xml // Maven configuration with dependencies and build plugins
└── src
├── main
│ ├── java/org/bookcart/ // Main application code
│ │ ├── base/ // Base test classes (e.g., BaseTest.java for setup/teardown)
│ │ ├── data/ // Test data factories (e.g., UserDataFactory.java)
│ │ ├── driver/ // WebDriver management (e.g., DriverManager.java)
│ │ ├── flows/ // Business logic flows (e.g., LoginFlow.java, UserRegistrationFlow.java)
│ │ ├── model/ // Data models (e.g., User.java)
│ │ ├── pages/ // Page Object Model classes (e.g., LoginPage.java, RegisterPage.java)
│ │ └── util/ // Utility classes for various common functionalities:
│ │ ├── ConfigManager.java // Loads and manages configuration properties
│ │ ├── CredentialsManager.java // Retrieves user credentials based on the environment
│ │ ├── MessageUtils.java // Handles common messages (e.g., error/info messages)
│ │ ├── ScreenshotUtils.java // Captures screenshots for reporting, especially on failures
│ │ ├── WaitUtils.java // Provides explicit wait methods for synchronizing tests
│ │ └── logging/ // Custom logging utilities:
│ │ ├── CustomLogger.java // Wrapper for logging functionality (using SLF4J/Logback)
│ │ └── LogManager.java // Factory for instantiating and managing loggers
│ └── resources/ // Application configuration files
│ ├── config.properties // Environment URLs, credentials, and other settings
│ └── logback.xml // Logging configuration (patterns, output locations)
└── test
├── java/org/bookcart/ // Test code
│ ├── login/ // Login-related test classes:
│ ├── providers/ // Data providers for tests:
│ │ └── UserDataProviders.java // Supplies dynamic test data for user-related tests
│ └── userregistration/ // User registration test
└── resources/ // Test configuration files
├── allure.properties // Configuration for Allure reporting
├── error-messages.properties // Common error messages used in tests
└── testng.xml // TestNG suite configuration for test execution
```
## Best Practices
### Logger Usage
```java
// Good
logger.info("Loading page: {}", url);
// Avoid
System.out.println("Loading page: " + url);
```
### Environment Isolation
```bash
# Never commit production credentials
# Keep sensitive data in environment variables
```
### Allure Reporting
**Add the necessary Annotations in test**
Example:
```java
@Test(dataProviderClass = UserDataProviders.class,
dataProvider = "invalidRegistrationData")
@Description("Verify that registration fails when user enters existing username")
@TmsLink("CEL-TC-46")
@Severity(SeverityLevel.CRITICAL)
```
**Add proper Step when needed**
Example:
```java
@Step("Entering Credentials")
public void enterCredentials(String username, String password) {
sendKeys(username, usernameTextField);
sendKeys(password, passwordTextField);
}
```
### Lombok Models
```java
@Getter
@Builder
public class User {
private final String username;
private final String password;
}
```
### Data-Driven Testing
```java
@DataProvider
public Object[][] invalidLogins() {
return new Object[][]{
{"invalidUser", "wrongPass"},
{"lockedUser", "secret123"}
};
}
```
## Future Roadmap
- Add BrowserStack Integration
- Create CI/CD Pipeline
- Grouping Tests
- Parallel Testing -TestNG parallel test runs
- Docker Support - Containerized test execution
## Report Issues
- [GitHub Issues](https://github.com/akashgkrishna/BookCart/issues)
## License
This project is licensed under the [MIT License](https://github.com/akashgkrishna/BookCart/blob/main/LICENSE)