Skip to content

lvbronco/selenium-test-website-java

Repository files navigation

Selenium Test Website - Java Maven TestNG

A Java Maven TestNG project for testing Selenium automation and LambdaTest Tunnel features. This project provides comprehensive form validation testing scenarios using Java, Maven, and TestNG.

Features

  • Java Maven TestNG: Modern Java testing framework with Maven dependency management
  • Selenium WebDriver: Automated browser testing with Chrome headless support
  • WebDriverManager: Automatic ChromeDriver management
  • Comprehensive Test Suite: 13 test scenarios covering all validation cases
  • TestNG Integration: Advanced test configuration and reporting
  • CI/CD Ready: Headless browser support for continuous integration

Prerequisites

  • Java 11 or higher
  • Maven 3.6 or higher
  • Node.js (version 14 or higher) - for running the website server
  • Chrome browser (for Selenium WebDriver)

Quick Start

1. Start the Website Server

First, start the Node.js server from the original project:

# Navigate to the original project directory
cd /Users/matthewedwards/selenium-test-website

# Install dependencies (if not already done)
npm install

# Start the server
npm start

The website will be available at http://localhost:3000

2. Run Java Tests

# Navigate to the Java project directory
cd /Users/matthewedwards/selenium-test-website-java

# Run all tests
mvn test

# Run tests with verbose output
mvn test -Dtest=FormValidationTest

# Run specific test method
mvn test -Dtest=FormValidationTest#testValidFormSubmission

Project Structure

selenium-test-website-java/
├── pom.xml                          # Maven configuration
├── testng.xml                       # TestNG suite configuration
├── README.md                        # This file
├── .gitignore                       # Git ignore file
└── src/
    ├── main/java/
    │   └── com/selenium/utils/
    │       └── FormHelper.java      # Helper class for form interactions
    └── test/java/
        └── com/selenium/tests/
            ├── BaseTest.java        # Base test class with setup/teardown
            └── FormValidationTest.java  # All test cases

Test Coverage

The test suite includes comprehensive validation scenarios:

  • Valid form submission → Success page
  • Empty form submission → All error messages
  • Invalid email format → Email error
  • Invalid phone format → Phone error
  • Short message → Message error
  • Short name → Name error
  • Clear button functionality → Form reset
  • Multiple validation errors → Multiple error messages
  • Valid phone formats → Various phone number formats
  • Real-time validation → Field blur validation
  • Form persistence → Data preserved on validation errors
  • Success page elements → Success page verification

Running Tests

Run All Tests

mvn test

Run Specific Test Class

mvn test -Dtest=FormValidationTest

Run Specific Test Method

mvn test -Dtest=FormValidationTest#testValidFormSubmission

Run with TestNG Groups

# Run only smoke tests
mvn test -Dgroups=smoke

# Run only validation tests
mvn test -Dgroups=validation

Run with Different Browsers

# Run with visible browser (for debugging)
# Edit BaseTest.java and comment out: chromeOptions.addArguments("--headless");

Test Configuration

  • Browser: Chrome (headless mode for CI/CD)
  • Timeout: 10 seconds for element waits
  • Base URL: http://localhost:3000
  • Test Framework: TestNG
  • Parallel Execution: 2 threads

Element Locators

The tests use the same element selectors as the Python version:

  • Name field: #name-input
  • Email field: #email-input
  • Phone field: #phone-input
  • Message field: #message-input
  • Submit button: #submit-btn
  • Clear button: #clear-btn
  • Error messages: #name-error, #email-error, #phone-error, #message-error

TestNG Configuration

The testng.xml file provides:

  • Test Groups: smoke, validation, functionality
  • Parallel Execution: Methods run in parallel with 2 threads
  • Reporters: XML and JUnit report generation
  • Test Order: Preserves test execution order

Maven Dependencies

  • Selenium WebDriver 4.15.2: Browser automation
  • TestNG 7.8.0: Testing framework
  • WebDriverManager 5.6.2: Automatic driver management
  • Maven Surefire Plugin 3.2.2: Test execution

Troubleshooting

Common Issues

  1. ChromeDriver issues: WebDriverManager automatically downloads ChromeDriver
  2. Port conflicts: Ensure the website is running on port 3000
  3. Headless mode: Tests run in headless mode by default; remove --headless from BaseTest.java for visual debugging
  4. Java version: Ensure Java 11+ is installed and configured

Debug Mode

Enable visible browser for debugging:

  1. Edit BaseTest.java
  2. Comment out: chromeOptions.addArguments("--headless");
  3. Run tests to see browser interactions

Test Reports

TestNG generates reports in:

  • target/surefire-reports/ - Surefire reports
  • target/testng-results/ - TestNG reports

LambdaTest Tunnel Integration

Setup LambdaTest Tunnel

  1. Install LambdaTest CLI:

    npm install -g @lambdatest/cli
  2. Set up tunnel:

    lt tunnel --port 3000
  3. Update BaseTest.java to use tunnel URL instead of localhost

Development

Adding New Tests

  1. Create new test methods in FormValidationTest.java
  2. Use @Test annotation with description
  3. Add to testng.xml if needed
  4. Follow existing patterns for assertions

Customizing Test Configuration

  • Base URL: Modify baseUrl in BaseTest.java
  • Timeouts: Adjust Duration.ofSeconds(10) in BaseTest.java
  • Browser Options: Modify ChromeOptions in BaseTest.java
  • Parallel Execution: Update testng.xml

License

MIT License - Feel free to use this for testing purposes.

About

LambdaTest - Trial

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published