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.
- Features
- Prerequisites
- Installation
- Configuration
- Execution
- Logging
- Project Structure
- Best Practices
- Future Roadmap
- License
- Environment Config: Easily switch between QA, Staging, and Production via
config.propertiesand 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.
- Java 22 JDK
- Maven 3.6+
- Chrome Browser (latest)
- IDE (IntelliJ/Eclipse/VSCode)
- Clone the repository:
git clone git@github.com:akashgkrishna/BookCart.git - Build the project:
mvn clean install
- Edit
src/main/resources/config.propertiesto modify environment URLs - Supported environments: QA, Prod, Staging
- Default environment: QA
# 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
<!-- Configure logging patterns and output locations -->
<root level="trace">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
- 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
# Browser configuration
browser=chrome
headless=trueSafari's settings need to be adjusted to allow automation. Follow these steps:
-
Enable the Develop Menu:
Open Safari and go to Safari > Preferences > Advanced. Then, check the box that says "Show Develop menu in menu bar". -
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. -
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.
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:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>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.results.directory=target/allure-resultsinvalid.username=User Name is not available
invalid.password=Password requirements not met<listeners>
<listener class-name="io.qameta.allure.testng.AllureTestNg"/>
</listeners>mvn testmvn test -Denv=prod-Denv=qa(default)-Denv=staging-Denv=prod
mvn allure:servepublic class BasicTest extends BaseTest {
@Test
public void exampleTest() {
logger.info("Using credentials: {}", username);
logger.error("Validation failed!");
}
}14:23:45 INFO [TestNG] o.b.BasicTest - Using credentials: test01
14:23:46 ERROR [TestNG] o.b.BasicTest - Validation failed!
├── 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
// Good
logger.info("Loading page: {}", url);
// Avoid
System.out.println("Loading page: " + url);# Never commit production credentials
# Keep sensitive data in environment variables
Add the necessary Annotations in test Example:
@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:
@Step("Entering Credentials")
public void enterCredentials(String username, String password) {
sendKeys(username, usernameTextField);
sendKeys(password, passwordTextField);
}@Getter
@Builder
public class User {
private final String username;
private final String password;
}@DataProvider
public Object[][] invalidLogins() {
return new Object[][]{
{"invalidUser", "wrongPass"},
{"lockedUser", "secret123"}
};
}- Add BrowserStack Integration
- Create CI/CD Pipeline
- Grouping Tests
- Parallel Testing -TestNG parallel test runs
- Docker Support - Containerized test execution
This project is licensed under the MIT License