This repository demonstrates a test automation framework that integrates Behavior-Driven Development (BDD) principles with the Page Object Model (POM) design pattern. The framework leverages Selenium WebDriver for browser automation, Cucumber for writing test scenarios in Gherkin, and TestNG for test execution, including support for parallel test runs. Built with Maven for project management, this Proof of Concept (POC) provides a scalable and maintainable foundation for automated testing.
Before setting up the project, ensure the following tools are installed on your system:
- Java Development Kit (JDK) 8 or higher: Required to compile and run the Java-based framework.
- Maven: Used for dependency management and build automation.
- An Integrated Development Environment (IDE): Recommended options include IntelliJ IDEA or Eclipse.
- A web browser: Such as Chrome or Firefox, for test execution.
Note: This project uses WebDriverManager to automatically manage WebDriver binaries (e.g., ChromeDriver, GeckoDriver), so manual setup of WebDriver executables is not required.
Follow these steps to set up the project on your local machine:
-
Clone the repository:
git clone https://github.com/your-repo-url.git
Replace
your-repo-urlwith the actual repository URL. -
Open the project in your IDE: Launch IntelliJ IDEA, Eclipse, or your preferred IDE and import the project as a Maven project.
-
Download dependencies: Allow the IDE to resolve Maven dependencies automatically. If necessary, run the following command in the terminal from the project root:
mvn clean install
This ensures all required libraries are downloaded and the project is built successfully.
To execute the test suite:
-
Using the IDE:
- Navigate to
src/test/java/runners/TestRunner.java. - Right-click the file and select "Run" to execute the tests via TestNG.
- Navigate to
-
Using the terminal: Run the following Maven command from the project root:
mvn clean test
This will trigger the Cucumber scenarios defined in the feature files, with TestNG managing the execution, including parallel test runs where configured.
The framework is organized into the following key directories and components:
-
src/main/resources/Features: Contains Cucumber feature files written in Gherkin. For this demo, the fileloginFeature2.featureshowcases a sample login scenario. -
src/test/java/stepDefinition: Houses step definition classes (e.g.,LoginPageStepDefinition.java) that map Gherkin steps to executable Java code, implementing the test logic. -
src/test/java/pageObjects: Contains page object classes that encapsulate web page elements and interactions, adhering to the POM design pattern for better maintainability and reusability. -
src/test/java/runners: Includes theTestRunner.javaclass, which uses TestNG to configure and initiate Cucumber test execution, enabling features like parallel running. -
target/cucumber-reports: The directory where test execution reports are generated post-run.
The pom.xml file in the project root manages all dependencies and build configurations using Maven.
After running the tests, detailed HTML reports are generated in the target/cucumber-reports directory. To view the results:
- Navigate to
target/cucumber-reports/index.html. - Open the file in a web browser to explore the test outcomes, including pass/fail statuses and step-by-step execution details.
This framework highlights the following capabilities:
-
Behavior-Driven Development (BDD): Utilizes Cucumber and Gherkin to write tests that are readable by both technical and non-technical stakeholders.
-
Page Object Model (POM): Organizes code into page-specific classes, enhancing reusability and reducing maintenance effort.
-
Parallel Execution: Leverages TestNG to run tests concurrently, optimizing execution time for larger test suites.
-
Automated Reporting: Provides comprehensive HTML reports via Cucumber, offering clear insights into test results.
This POC serves as a starting point for building more complex and tailored test automation solutions.
Feel free to explore and adapt this demo project to meet your testing needs! For additional resources, refer to the documentation of the technologies used: Selenium, Cucumber, TestNG, and Maven.