[ PROMPT_NODE_25031 ]
Playwright Java – Config
[ SKILL_DOCUMENTATION ]
# Playwright Java – Project Configuration
## Maven POM (`pom.xml`)
```xml
4.0.0
com.company
playwright-tests
1.0-SNAPSHOT
17
17
17
UTF-8
1.44.0
5.10.2
2.27.0
1.9.22
com.microsoft.playwright
playwright
${playwright.version}
org.junit.jupiter
junit-jupiter
${junit.version}
test
org.junit.jupiter
junit-jupiter-params
${junit.version}
test
io.qameta.allure
allure-junit5
${allure.version}
test
org.assertj
assertj-core
3.25.3
test
com.fasterxml.jackson.core
jackson-databind
2.17.1
net.datafaker
datafaker
2.2.2
ch.qos.logback
logback-classic
1.5.6
org.apache.maven.plugins
maven-surefire-plugin
3.2.5
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
${browser}
${headless}
${baseUrl}
${project.build.directory}/allure-results
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4
org.aspectj
aspectjweaver
${aspectj.version}
io.qameta.allure
allure-maven
2.12.0
${allure.version}
```
---
## `test.properties`
```properties
# src/test/resources/test.properties
baseUrl=https://your-app.com
apiBaseUrl=https://api.your-app.com
browser=chromium
headless=true
slowMo=0
defaultTimeout=30000
navigationTimeout=60000
```
---
## `ConfigReader.java`
```java
package com.company.tests.config;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public final class ConfigReader {
private static final Properties props = new Properties();
static {
try (InputStream in = ConfigReader.class
.getClassLoader()
.getResourceAsStream("test.properties")) {
if (in != null) props.load(in);
} catch (IOException e) {
throw new RuntimeException("Cannot load test.properties", e);
}
}
public static String getBaseUrl() {
return System.getProperty("baseUrl", props.getProperty("baseUrl", "http://localhost:3000"));
}
public static int getDefaultTimeout() {
String val = System.getProperty("defaultTimeout", props.getProperty("defaultTimeout", "30000"));
return Integer.parseInt(val);
}
public static boolean isHeadless() {
return Boolean.parseBoolean(System.getProperty("headless", props.getProperty("headless", "true")));
}
}
```
---
## Browser Installation (First-Time Setup)
```bash
# Install browsers for current OS
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install"
# Install with system dependencies (needed in CI/Docker)
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install --with-deps"
# Install specific browser only
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install chromium"
```
---
## Running Tests
```bash
# All tests, headless Chromium
mvn test
# Specific browser
mvn test -Dbrowser=firefox
# Headed mode (debug)
mvn test -Dheadless=false -DslowMo=500
# Single test class
mvn test -Dtest=LoginTest
# Generate Allure report
mvn allure:serve
# Export report to directory
mvn allure:report
```
---
## Docker / CI Environment
```dockerfile
FROM mcr.microsoft.com/playwright/java:v1.44.0-jammy
WORKDIR /app
COPY . .
RUN mvn dependency:resolve
CMD ["mvn", "test", "-Dheadless=true"]
```