Skip to content

tediyo/SCM-Java_set-up

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selenium Cucumber Java Test Automation Framework

This project is a test automation framework using Selenium WebDriver, Cucumber (BDD), Java, and Gherkin syntax.

Prerequisites

  • Java JDK 11 or higher
  • Maven 3.6+
  • IDE (IntelliJ IDEA, Eclipse, or VS Code recommended)
  • Chrome, Firefox, or Edge browser installed

Project Structure

SCM/
├── pom.xml                              # Maven configuration file
├── README.md                            # Project documentation
└── src/
    └── test/
        ├── java/
        │   └── com/
        │       └── scm/
        │           ├── runners/
        │           │   └── RunCucumberTest.java    # Test runner class
        │           ├── steps/
        │           │   ├── Hooks.java              # Before/After hooks
        │           │   ├── GoogleSearchSteps.java  # Step definitions for Google search
        │           │   └── ErmishoeLoginSteps.java # Step definitions for Ermishoe login
        │           └── utils/
        │               └── DriverManager.java      # WebDriver management utility
        └── resources/
            └── features/
                ├── google_search.feature           # Google search feature file
                └── ermishoe_login.feature          # Ermishoe login feature file

Setup Instructions

1. Clone or download the project

2. Install dependencies

Maven will automatically download all dependencies when you build the project.

mvn clean install

3. Verify setup

Run the tests to verify everything is set up correctly:

mvn test

Or run tests with a specific tag:

mvn test -Dcucumber.filter.tags="@smoke"

Running Tests

Run all tests

mvn test

Run tests with specific tags

# Run only smoke tests
mvn test -Dcucumber.filter.tags="@smoke"

# Run only regression tests
mvn test -Dcucumber.filter.tags="@regression"

# Run both smoke and regression
mvn test -Dcucumber.filter.tags="@smoke or @regression"

Run tests with specific browser

# Run with Chrome (default)
mvn test -Dbrowser=chrome

# Run with Firefox
mvn test -Dbrowser=firefox

# Run with Edge
mvn test -Dbrowser=edge

Run a specific feature file

  • PowerShell (Windows) requires quoting -D properties and prefers classpath paths:
.\mvnw.cmd test "-Dcucumber.features=classpath:features/ermishoe_login.feature" "-Dbrowser=chrome"
  • macOS/Linux:
./mvnw test -Dcucumber.features=classpath:features/google_search.feature -Dbrowser=chrome
  • To run all tests (runner discovers features on classpath):
.\mvnw.cmd test

Writing Features

Feature files use Gherkin syntax and are located in src/test/resources/features/.

Example:

Feature: Google Search
  As a user
  I want to search on Google
  So that I can find information on the internet

  @smoke
  Scenario: Search for a term on Google
    Given I am on the Google homepage
    When I search for "Selenium WebDriver"
    Then I should see search results containing "Selenium"

Writing Step Definitions

Step definitions are Java classes in src/test/java/com/scm/steps/ that implement the Gherkin steps.

Example:

@Given("I am on the Google homepage")
public void i_am_on_the_google_homepage() {
    driver.get("https://www.google.com");
}

Test Reports

Enhanced Reporting System

After running tests, multiple comprehensive reports are generated in target/cucumber-reports/:

  • HTML Report: cucumber-html-report.html - Interactive report with screenshots, logs, and detailed results
  • Timeline Report: timeline/timeline.html - Visual timeline showing execution flow
  • JSON Report: cucumber.json - Machine-readable format for CI/CD integration
  • JUnit XML: cucumber.xml - Standard XML format for build tools
  • Usage Report: cucumber-usage.json - Performance metrics and step execution times
  • Rerun File: rerun.txt - List of failed scenarios for easy rerunning
  • Report Index: index.html - Central hub to access all reports

Quick Access

  • View all reports: Open target/cucumber-reports/index.html in your browser
  • Main HTML report: Open target/cucumber-reports/cucumber-html-report.html
  • Timeline visualization: Open target/cucumber-reports/timeline/timeline.html

Report Features

  • ✅ Automatic screenshot capture on test failures
  • ✅ Detailed scenario logs with timestamps
  • ✅ Browser information tracking
  • ✅ Performance metrics and execution times
  • ✅ Visual timeline for parallel execution
  • ✅ Failed test rerun file generation

📖 For detailed information about reports, see REPORTS.md

Key Components

DriverManager

Manages WebDriver instances and supports multiple browsers (Chrome, Firefox, Edge). Automatically handles driver setup using WebDriverManager.

Hooks

Contains @Before and @After hooks that:

  • Initialize the WebDriver before each scenario
  • Log scenario start time and browser information
  • Take screenshots on test failure with timestamped names
  • Log scenario completion time and status
  • Clean up the WebDriver after each scenario

Test Runner

RunCucumberTest.java is the JUnit test runner that executes Cucumber scenarios.

Configuration

Browser Selection

Set the browser using system property:

-Dbrowser=chrome

Supported browsers: chrome, firefox, edge

Headless Mode

To run tests in headless mode, uncomment the headless options in DriverManager.java:

chromeOptions.addArguments("--headless");

Dependencies

  • Selenium WebDriver 4.15.0 - Browser automation
  • Cucumber 7.14.0 - BDD testing framework
  • JUnit 5.10.0 - Test execution framework
  • WebDriverManager 5.6.2 - Automatic driver management

Troubleshooting

Browser driver issues

WebDriverManager should automatically download the correct driver. If you encounter issues:

  1. Make sure you have internet connectivity
  2. Check that your browser is up to date
  3. Manually specify driver path if needed

Tests failing

  1. Check that the target website is accessible
  2. Verify that selectors match the current page structure
  3. Check screenshots in the report for visual debugging

Next Steps

  1. Add more feature files for your application
  2. Create page object model classes for better organization
  3. Integrate with CI/CD pipelines
  4. Add data-driven testing with Cucumber data tables
  5. Configure parallel test execution

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published