Skip to content

Commit 0a8d0e2

Browse files
Initial commit
0 parents  commit 0a8d0e2

36 files changed

+1622
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
6+
7+
### IntelliJ IDEA ###
8+
.idea
9+
*.iws
10+
*.iml
11+
*.ipr
12+
out/
13+
!**/src/main/**/out/
14+
!**/src/test/**/out/
15+

README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# Test Automation Framework - UI Automation with Playwright, Spring Boot and JUnit 5
2+
3+
## Overview
4+
5+
This UI Test Automation Framework is designed **to automate end-to-end UI testing of web applications**.
6+
The framework leverages **Playwright** for browser automation, **JUnit 5** for test structuring and execution,
7+
and **Gradle** as the build tool. **Spring Boot** is used for **Dependency Injection (DI) and
8+
Configuration Management**.
9+
**Log4j2** handles logging, and **Allure** is used to generate rich test reports.
10+
11+
Additionally, this framework supports parallel test execution, the ability to capture screenshots and videos during test
12+
execution,
13+
and integrates configuration from an `application.yml` file to set up environment-specific settings, such as browser
14+
type and timeout.
15+
16+
## Key Features
17+
18+
- **Playwright Integration:** Automates UI testing across various browsers (Chromium, Firefox, and WebKit),
19+
simulating real user interactions like clicks, form submissions, and validation.
20+
- **JUnit 5:** Organizes tests and provides advanced features such as parallel test execution, flexible assertions,
21+
and lifecycle management.
22+
- **Parallel Execution:** The framework supports parallel execution of tests, improving test suite execution times.
23+
You can configure the number of concurrent threads and control execution modes for classes and tests.
24+
- **Spring Boot Integration:** Leverages Spring Boot for managing dependencies and application configuration
25+
via @Configuration and @ConfigurationProperties annotations, which makes the setup process highly configurable and
26+
flexible.
27+
- **Log4j2 for Logging:** Provides detailed logging to track test steps and errors. Configured via Log4j2’s XML
28+
configuration.
29+
- **Allure Reporting:** Generates detailed, visually appealing test reports that include test status (pass/fail),
30+
execution times, logs, screenshots, and videos.
31+
- **Video and Screenshots:** Capture videos and screenshots during test execution for easier debugging and issue
32+
tracking.
33+
These are automatically attached to the Allure reports.
34+
- **JUnit 5 Configuration:** Supports configuration for parallel test execution, which helps improve test performance
35+
by running tests concurrently.
36+
37+
## Technologies Used
38+
39+
Given test automation project is built with next key frameworks and technologies:
40+
41+
- [Java 21](https://openjdk.org/projects/jdk/21/) as the programming language.
42+
- [Gradle 8.12.1](https://gradle.org/) build tool for managing dependencies and running the test suite.
43+
- [Spring Boot](https://spring.io/projects/spring-boot) for bean lifecycle management, dependency injection and
44+
configuration properties;
45+
- [Playwright](https://playwright.dev/) a Node.js library that enables reliable browser automation.
46+
Supports Chromium, Firefox, and WebKit.
47+
- [Log4j2](https://logging.apache.org/log4j/) a powerful logging library to manage logs from your automated tests.
48+
- [Project Lombok](https://projectlombok.org/) is a Java library that reduces boilerplate code by generating getters,
49+
setters, constructors, and other common methods through annotations.
50+
- [JUnit 5](https://junit.org/junit5/) a modern testing framework that supports features such as parallel test
51+
execution,
52+
flexible assertions, and annotations.
53+
- [Allure](https://docs.qameta.io/allure/) a framework for generating beautiful and comprehensive test reports,
54+
including details like screenshots,
55+
videos, and execution times.
56+
57+
## Getting Started
58+
59+
### Prerequisites
60+
61+
- JDK 21 or higher.
62+
- Gradle for build and dependency management.
63+
- Playwright is included as a Gradle dependency and will be installed automatically during the build process
64+
65+
### Installation
66+
67+
1. [Fork](https://github.com/alex-sviatenko/playwright-java-springboot-test/fork) the repository.
68+
2. Clone the repository and navigate to the project
69+
70+
```
71+
$ git clone https://github.com/[your_username]/playwright-java-springboot-test.git
72+
$ cd playwright-java-springboot-test
73+
```
74+
75+
3. Create environment variables for your testing credentials.
76+
77+
To keep sensitive data (such as login credentials) secure and separate from your codebase, the test framework uses
78+
**environment variables** for configuration. Specifically, the `email` and `password` required for logging into
79+
[Automation Exercise](https://www.automationexercise.com/) are retrieved from environment variables.
80+
81+
For Linux/macOS:
82+
83+
```bash
84+
export TEST_EMAIL=your-temp-email@example.com
85+
export TEST_PASSWORD=your-temp-password
86+
```
87+
88+
For Windows:
89+
90+
```bash
91+
set TEST_EMAIL=your-temp-email@example.com
92+
set TEST_PASSWORD=your-temp-password
93+
```
94+
95+
4. Configure the test properties:
96+
97+
The `application.yml` will reference these environment variables. The email and password will be read at runtime.
98+
99+
**Example `application.yml`**:
100+
101+
```yaml
102+
test:
103+
email: ${TEST_EMAIL}
104+
password: ${TEST_PASSWORD}
105+
```
106+
107+
5. Build the project and run tests using Gradle:
108+
109+
```shell
110+
./gradlew test
111+
```
112+
113+
Overriding YAML properties via Command Line in Spring Boot
114+
115+
```shell
116+
./gradlew test -Dtest.browser=firefox -Dtest.headless=true
117+
```
118+
119+
6. Generate Allure Reports:
120+
121+
```shell
122+
./gradlew allureServe
123+
```
124+
125+
## Parallel Test Execution with JUnit 5
126+
127+
The framework is configured to run tests in parallel to speed up execution.
128+
The following settings are applied in the `junit-platform.properties` file:
129+
130+
- **Parallel Execution Enabled:** Tests are executed in parallel to improve speed.
131+
- **Test Execution Configuration:**
132+
- **same_thread:** Ensures tests run on the same thread by default.
133+
- **concurrent:** Runs classes concurrently.
134+
- **fixed:** A fixed parallelism strategy is used with 2 threads running tests concurrently.
135+
136+
You can modify these properties in the `junit-platform.properties` file to adjust the parallel execution as needed.
137+
138+
```properties
139+
junit.jupiter.execution.parallel.enabled=true
140+
junit.jupiter.execution.parallel.mode.default=same_thread
141+
junit.jupiter.execution.parallel.mode.classes.default=concurrent
142+
junit.jupiter.execution.parallel.config.strategy=fixed
143+
junit.jupiter.execution.parallel.config.fixed.parallelism=2
144+
```
145+
146+
## Allure Reporting
147+
148+
Allure is used for generating comprehensive and visually appealing test reports. It displays test results,
149+
execution times, logs, and attachments such as screenshots and videos.
150+
To configure Allure reporting, follow these steps:
151+
152+
1. Allure Properties: Set the directory where Allure should store the test results by adding the following to the
153+
`allure.properties` file:
154+
155+
```properties
156+
allure.results.directory=build/allure-results
157+
```
158+
159+
2. Test Attachments (Screenshots and Videos):
160+
161+
- The framework is set to capture screenshots and record videos during test execution.
162+
- Videos are stored in the directory specified in your `application.yml` configuration, under **test.video.path**.
163+
- Allure automatically attaches the screenshots and videos to the report when test is failed.
164+
165+
3. Generate the Allure Report:
166+
167+
- After running your tests, you can view the Allure report with:
168+
169+
```shell
170+
./gradlew allureServe
171+
```
172+
173+
## Application Configuration
174+
175+
The test framework can be customized through the `application.yml` file.
176+
Here you can define settings related to the test environment, such as the base URL, email,
177+
password, browser settings, and video capture configurations.
178+
It provides an organized way to configure test properties that are injected into the test classes.
179+
180+
- The ***@Configuration*** annotation allows you to create configuration classes that bind values from the
181+
`application.yml` file to fields in the class.
182+
- The ***@ConfigurationProperties*** annotation is used to map the configuration values automatically to the fields in
183+
the class.
184+
185+
### Example Configuration (application.yml): ###
186+
187+
```yaml
188+
application:
189+
url: https://www.automationexercise.com/
190+
email: ${TEST_EMAIL}
191+
password: ${TEST_PASSWORD}
192+
193+
test:
194+
browser: chromium
195+
headless: true
196+
slow:
197+
motion: 100
198+
timeout: 10000
199+
video:
200+
enabled: true
201+
path: build/test-video/
202+
size:
203+
width: 1280
204+
height: 720
205+
screen:
206+
size:
207+
width: 1920
208+
height: 1080
209+
```
210+
211+
- **browser:** Specifies which browser to use (e.g., chromium, firefox, webkit).
212+
- **headless:** Whether to run the browser in headless mode (no GUI).
213+
- **timeout:** Time in milliseconds for test steps to complete before timing out.
214+
- **video:** Configuration for enabling video recording, including the storage path and resolution.
215+
- **screen:** Configuration for capturing screenshots, including screen size

build.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '3.4.2'
4+
id 'io.spring.dependency-management' version '1.1.7'
5+
id("io.qameta.allure") version "2.12.0"
6+
id("io.freefair.lombok") version "8.12"
7+
}
8+
9+
group = 'com'
10+
version = '0.0.1-SNAPSHOT'
11+
12+
java {
13+
toolchain {
14+
languageVersion = JavaLanguageVersion.of(21)
15+
}
16+
}
17+
18+
repositories {
19+
mavenCentral()
20+
}
21+
22+
dependencies {
23+
// JUnit for testing framework
24+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.4'
25+
26+
// Playwright for browser automation
27+
implementation 'com.microsoft.playwright:playwright:1.49.0'
28+
29+
// Logging-related dependencies (Log4j2)
30+
implementation 'org.apache.logging.log4j:log4j-core:2.24.3'
31+
implementation 'org.apache.logging.log4j:log4j-api:2.24.3'
32+
33+
// SLF4J NOP (No-Operation) provider to suppress SLF4J logging
34+
// If you are using Log4j2 and don't want SLF4J logs, this ensures no logs are printed by SLF4J.
35+
implementation 'org.slf4j:slf4j-nop:2.0.16' // NOP provider to suppress SLF4J logs
36+
37+
// Spring Boot Starter Test with exclusions for unnecessary dependencies
38+
// Excluding mockito-core and Spring Boot logging to use Log4j2 as the logger instead
39+
implementation('org.springframework.boot:spring-boot-starter-test') {
40+
exclude group: 'org.mockito', module: 'mockito-core'
41+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
42+
}
43+
44+
// Allure dependency for test reporting
45+
implementation 'io.qameta.allure:allure-junit-platform:2.29.1'
46+
}
47+
48+
test {
49+
systemProperties = System.getProperties() as Map<String, ?>
50+
useJUnitPlatform()
51+
}
52+
53+
bootJar {
54+
enabled = false
55+
}

gradle/wrapper/gradle-wrapper.jar

42.6 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)