Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ready for use Test Automation Framework using Java, Playwright, Spring Boot and JUnit

NotificationsYou must be signed in to change notification settings

alex-sviatenko/playwright-java-springboot-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This UI Test Automation Framework is designedto automate end-to-end UI testing of web applications.The framework leveragesPlaywright for browser automation,JUnit 5 for test structuring and execution,andGradle as the build tool.Spring Boot is used forDependency Injection (DI) andConfiguration Management.Log4j2 handles logging, andAllure is used to generate rich test reports.

Additionally, this framework supports parallel test execution, the ability to capture screenshots and videos during testexecution,and integrates configuration from anapplication.yml file to set up environment-specific settings, such as browsertype and timeout.

Key Features

  • Playwright Integration: Automates UI testing across various browsers (Chromium, Firefox, and WebKit),simulating real user interactions like clicks, form submissions, and validation.
  • JUnit 5: Organizes tests and provides advanced features such as parallel test execution, flexible assertions,and lifecycle management.
  • Parallel Execution: The framework supports parallel execution of tests, improving test suite execution times.You can configure the number of concurrent threads and control execution modes for classes and tests.
  • Spring Boot Integration: Leverages Spring Boot for managing dependencies and application configurationvia @Configuration and @ConfigurationProperties annotations, which makes the setup process highly configurable andflexible.
  • Log4j2 for Logging: Provides detailed logging to track test steps and errors. Configured via Log4j2’s XMLconfiguration.
  • Allure Reporting: Generates detailed, visually appealing test reports that include test status (pass/fail),execution times, logs, screenshots, and videos.
  • Video and Screenshots: Capture videos and screenshots during test execution for easier debugging and issuetracking.These are automatically attached to the Allure reports.
  • JUnit 5 Configuration: Supports configuration for parallel test execution, which helps improve test performanceby running tests concurrently.

Technologies Used

Given test automation project is built with next key frameworks and technologies:

  • Java 21 as the programming language.
  • Gradle 8.12.1 build tool for managing dependencies and running the test suite.
  • Spring Boot for bean lifecycle management, dependency injection andconfiguration properties;
  • Playwright a Node.js library that enables reliable browser automation.Supports Chromium, Firefox, and WebKit.
  • Log4j2 a powerful logging library to manage logs from your automated tests.
  • Project Lombok is a Java library that reduces boilerplate code by generating getters,setters, constructors, and other common methods through annotations.
  • JUnit 5 a modern testing framework that supports features such as parallel testexecution,flexible assertions, and annotations.
  • Allure a framework for generating beautiful and comprehensive test reports,including details like screenshots,videos, and execution times.

Getting Started

Prerequisites

  • JDK 21 or higher.
  • Gradle for build and dependency management.
  • Playwright is included as a Gradle dependency and will be installed automatically during the build process

Installation

  1. Fork the repository.
  2. Clone the repository and navigate to the project
$ git clone https://github.com/[your_username]/playwright-java-springboot-test.git$ cd playwright-java-springboot-test
  1. Create environment variables for your testing credentials.

To keep sensitive data (such as login credentials) secure and separate from your codebase, the test framework usesenvironment variables for configuration. Specifically, theemail andpassword required for logging intoAutomation Exercise are retrieved from environment variables.

For Linux/macOS:

export TEST_EMAIL=your-temp-email@example.comexport TEST_PASSWORD=your-temp-password

For Windows:

set TEST_EMAIL=your-temp-email@example.comset TEST_PASSWORD=your-temp-password
  1. Configure the test properties:

Theapplication.yml will reference these environment variables. The email and password will be read at runtime.

Exampleapplication.yml:

test:email:${TEST_EMAIL}password:${TEST_PASSWORD}
  1. Build the project and run tests using Gradle:
./gradlewtest

Overriding YAML properties via Command Line in Spring Boot

./gradlewtest -Dtest.browser=firefox -Dtest.headless=true
  1. Generate Allure Reports:
./gradlew allureServe

Parallel Test Execution with JUnit 5

The framework is configured to run tests in parallel to speed up execution.The following settings are applied in thejunit-platform.properties file:

  • Parallel Execution Enabled: Tests are executed in parallel to improve speed.
  • Test Execution Configuration:
    • same_thread: Ensures tests run on the same thread by default.
    • concurrent: Runs classes concurrently.
    • fixed: A fixed parallelism strategy is used with 2 threads running tests concurrently.

You can modify these properties in thejunit-platform.properties file to adjust the parallel execution as needed.

junit.jupiter.execution.parallel.enabled=truejunit.jupiter.execution.parallel.mode.default=same_threadjunit.jupiter.execution.parallel.mode.classes.default=concurrentjunit.jupiter.execution.parallel.config.strategy=fixedjunit.jupiter.execution.parallel.config.fixed.parallelism=2

Allure Reporting

Allure is used for generating comprehensive and visually appealing test reports. It displays test results,execution times, logs, and attachments such as screenshots and videos.To configure Allure reporting, follow these steps:

  1. Allure Properties: Set the directory where Allure should store the test results by adding the following to theallure.properties file:
allure.results.directory=build/allure-results
  1. Test Attachments (Screenshots and Videos):
  • The framework is set to capture screenshots and record videos during test execution.
  • Videos are stored in the directory specified in yourapplication.yml configuration, undertest.video.path.
  • Allure automatically attaches the screenshots and videos to the report when test is failed.
  1. Generate the Allure Report:
  • After running your tests, you can view the Allure report with:
./gradlew allureServe

Application Configuration

The test framework can be customized through theapplication.yml file.Here you can define settings related to the test environment, such as the base URL, email,password, browser settings, and video capture configurations.It provides an organized way to configure test properties that are injected into the test classes.

  • The@Configuration annotation allows you to create configuration classes that bind values from theapplication.yml file to fields in the class.
  • The@ConfigurationProperties annotation is used to map the configuration values automatically to the fields inthe class.

Example Configuration (application.yml):

application:url:https://www.automationexercise.com/email:${TEST_EMAIL}password:${TEST_PASSWORD}test:browser:chromiumheadless:trueslow:motion:100timeout:10000video:enabled:truepath:build/test-video/size:width:1280height:720screen:size:width:1920height:1080
  • browser: Specifies which browser to use (e.g., chromium, firefox, webkit).
  • headless: Whether to run the browser in headless mode (no GUI).
  • timeout: Time in milliseconds for test steps to complete before timing out.
  • video: Configuration for enabling video recording, including the storage path and resolution.
  • screen: Configuration for capturing screenshots, including screen size

About

Ready for use Test Automation Framework using Java, Playwright, Spring Boot and JUnit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp