← BACK

cucumber-with-selenium

Java ⭐ 0

cucumber-with-selenium 🥒

Build Status
Version
License

This project demonstrates the integration of Cucumber with Selenium for automated end-to-end testing in Java. It provides a framework for writing behavior-driven development (BDD) test scenarios that are executed using Selenium WebDriver.

Table of Contents 📑

Project Description 📝

The cucumber-with-selenium repository showcases how to leverage Cucumber for defining acceptance tests in a human-readable format (Gherkin) and executing them with Selenium WebDriver for browser automation. This approach enhances collaboration between developers, testers, and business stakeholders by ensuring that the tests accurately reflect the desired behavior of the application.

Features ✨

  • Behavior-Driven Development (BDD): Define test scenarios using Gherkin syntax (.feature files).
  • Selenium WebDriver Integration: Automate browser interactions for end-to-end testing.
  • Java Project Structure: Organized Java project using Maven for dependency management.
  • Modular Step Definitions: Separate step definition classes for different functionalities (e.g., login, product management).
  • Edge Browser Support: Uses Microsoft Edge WebDriver for test execution.

Tech Stack 💻

  • Language: Java ☕
  • BDD Framework: Cucumber 7.15.0
  • Test Runner: JUnit 4.13.2
  • Web Automation: Selenium WebDriver 4.19.1
  • Browser Driver: EdgeDriver
  • Build Tool: Maven

Installation ⚙️

This project uses Maven for dependency management. To set up the project:

  1. Clone the repository:
    git clone https://github.com/phambaophuc/cucumber-with-selenium.git
    cd cucumber-with-selenium
    
  2. Ensure you have Java Development Kit (JDK) 17 or later installed.
  3. Ensure you have Maven installed.
  4. Download the Microsoft Edge WebDriver:
    • Make sure your Microsoft Edge browser is up to date.
    • Download the appropriate msedgedriver.exe for your system from the official Microsoft Edge WebDriver releases.
    • Place the msedgedriver.exe in a directory that is included in your system's PATH environment variable, or specify its path directly in the code if needed (though not recommended for general use).
  5. Build the project using Maven:
    mvn clean install
    

Usage 🚀

This project is designed to run automated tests against web applications. The tests are defined in .feature files and implemented in Java step definition classes.

Running Tests

To run all the defined Cucumber tests, you can execute the RunSteps class, which is configured as a JUnit test runner.

  1. Navigate to the src/test/java directory.
  2. Locate the RunSteps.java file.
  3. Execute the tests using your IDE (e.g., IntelliJ IDEA, Eclipse) by right-clicking on RunSteps.java and selecting 'Run' or 'Debug'.

Alternatively, you can run the tests from the command line using Maven:

mvn test

Example Scenarios:

Login Functionality:

  • Feature File: src/test/resources/features/login.feature
  • Step Definitions: src/test/java/stepdefinitions/LoginSteps.java
  • This scenario tests the user login process with valid and invalid credentials against a web application hosted at http://localhost:4000/login.

Product Management:

  • Create Product: Tests adding a new product via the UI (http://localhost:3001/#/booking/product/addProduct).
    • Step Definitions: CreateProductSteps.java
    • Feature File: create-product.feature
  • Edit Product: Tests modifying an existing product's details (http://localhost:3001/#/booking/product).
    • Step Definitions: EditProductSteps.java
    • Feature File: edit-product.feature
  • Delete Product: Tests removing a product from the management page (http://localhost:3001/#/account/role).
    • Step Definitions: DeleteProductSteps.java
    • Feature File: delete-product.feature
  • View Product Detail: Tests navigating to and viewing product details (http://localhost:4000/).
    • Step Definitions: DetailProductSteps.java
    • Feature File: detail-product.feature
  • Order Product: Tests the process of viewing a product and adding it to the cart (http://localhost:4000/).
    • Step Definitions: OrderProductSteps.java
    • Feature File: order-product.feature

User Registration:

  • Feature File: src/test/resources/features/register.feature
  • Step Definitions: src/test/java/stepdefinitions/RegisterSteps.java
  • This scenario tests the user registration flow, including form submission and validation, against a web application hosted at http://localhost:4000/register.

Note: The tests assume the target web applications are running locally on the specified ports (http://localhost:3001 and http://localhost:4000).

Project Structure 📁

cucumber-with-selenium/
├── .idea/
│   ├── encodings.xml
│   ├── misc.xml
│   ├── ui-designer.xml
│   └── vcs.xml
├── src/
│   ├── main/java/org/example/
│   │   └── Main.java
│   └── test/java/
│       ├── RunSteps.java
│       └── stepdefinitions/
│           ├── CreateProductSteps.java
│           ├── DeleteProductSteps.java
│           ├── DetailProductSteps.java
│           ├── EditProductSteps.java
│           ├── LoginSteps.java
│           ├── OrderProductSteps.java
│           └── RegisterSteps.java
│   └── test/resources/features/
│       ├── create-product.feature
│       ├── delete-product.feature
│       ├── detail-product.feature
│       ├── edit-product.feature
│       ├── login.feature
│       ├── order-product.feature
│       └── register.feature
├── pom.xml
└── README.md
  • .idea/: IntelliJ IDEA project configuration files.
  • src/main/java/: Contains the main application code (in this case, a simple Main class).
  • src/test/java/: Contains the test code.
    • RunSteps.java: The Cucumber test runner class.
    • stepdefinitions/: Contains the Java classes implementing the step definitions for the Gherkin scenarios.
  • src/test/resources/features/: Contains the Gherkin feature files (.feature).
  • pom.xml: The Maven project configuration file, defining dependencies and build settings.
  • README.md: This file.

License 📜

This project is not currently under any specified license. Please refer to the repository URL for more information.

Footer 📝

© 2024 phambaophuc/cucumber-with-selenium

Author: phambaophuc

Feel free to star ⭐, fork 🍴, and open issues ❗ for any improvements or bug reports.