Skip to content

Commit b74b607

Browse files
committed
Added docker configuration
1 parent 2cae700 commit b74b607

File tree

5 files changed

+116
-4
lines changed

5 files changed

+116
-4
lines changed

.github/workflows/playwright-tests.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ jobs:
1818
- name: Checkout repository
1919
uses: actions/checkout@v3
2020

21+
- name: Set up Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: '20'
25+
2126
# Step 2: Set up JDK 17 (adjust if you're using a different version)
2227
- name: Set up JDK 17
23-
uses: actions/setup-java@v3
28+
uses: actions/setup-java@v4
2429
with:
2530
java-version: '17'
2631
distribution: 'adopt'
@@ -47,6 +52,9 @@ jobs:
4752
restore-keys: |
4853
${{ runner.os }}-maven
4954
50-
# Step 4: Run Maven to execute Playwright tests
55+
- name: Install Playwright dependencies
56+
run: npx playwright install-deps
57+
58+
# Step 6: Run Maven to execute Playwright tests
5159
- name: Run Playwright Tests
5260
run: mvn verify

docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3.8'
2+
3+
services:
4+
webapp:
5+
build:
6+
context: ./react-todomvc
7+
ports:
8+
- "7002:7002"
9+
networks:
10+
- test-network
11+
healthcheck:
12+
test: ["CMD", "curl", "-f", "http://localhost:7002"]
13+
interval: 10s
14+
timeout: 5s
15+
retries: 5
16+
# Ensure the webapp service doesn't restart automatically
17+
restart: "no"
18+
19+
tests:
20+
build:
21+
context: ./todomvc-acceptance-tests
22+
depends_on:
23+
webapp:
24+
condition: service_healthy
25+
networks:
26+
- test-network
27+
volumes:
28+
- ./todomvc-acceptance-tests/target:/tests/target
29+
# Ensure the webapp service doesn't restart automatically
30+
environment:
31+
- APP_HOST_URL=http://webapp:7002
32+
user: "${UID}:${GID}"
33+
restart: "no"
34+
35+
networks:
36+
test-network:
37+
driver: bridge

react-todomvc/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use the official Node.js LTS image
2+
FROM node:16
3+
4+
# Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json
8+
COPY package*.json ./
9+
10+
# Install Node.js dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application code
14+
COPY . .
15+
16+
# Expose the port that your app runs on
17+
EXPOSE 7002
18+
19+
# Start the Node.js application
20+
CMD ["npm", "run", "serve"]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Use OpenJDK 17 slim as the base image
2+
FROM openjdk:17-slim
3+
4+
# Install dependencies
5+
RUN apt-get update && \
6+
apt-get install -y curl zip unzip && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
# Install SDKMAN! and Maven 3.9.9
10+
RUN curl -s "https://get.sdkman.io" | bash && \
11+
bash -c "source $HOME/.sdkman/bin/sdkman-init.sh && \
12+
sdk install maven 3.9.9"
13+
14+
# Set Maven environment variables
15+
ENV MAVEN_HOME /root/.sdkman/candidates/maven/current
16+
ENV PATH "$MAVEN_HOME/bin:$PATH"
17+
18+
# Verify Maven installation
19+
RUN mvn -version
20+
21+
# Install curl and update CA certificates
22+
RUN apt-get update && \
23+
apt-get install -y --no-install-recommends curl ca-certificates && \
24+
rm -rf /var/lib/apt/lists/*
25+
26+
# Install Node.js and npm
27+
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
28+
apt-get install -y nodejs && \
29+
rm -rf /var/lib/apt/lists/*
30+
31+
# Install Playwright dependencies
32+
RUN npx playwright install-deps
33+
34+
# Test internet connectivity
35+
RUN curl -I https://repo.maven.apache.org/maven2/
36+
37+
# Set the working directory inside the container
38+
WORKDIR /tests
39+
40+
# Copy the Maven project files to the container
41+
COPY . .
42+
43+
# Run Maven to execute the tests
44+
CMD ["mvn", "verify"]

todomvc-acceptance-tests/src/main/java/com/serenitydojo/playwright/todomvc/pageobjects/TodoMvcAppPage.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.microsoft.playwright.Locator;
44
import com.microsoft.playwright.Page;
5+
import org.apache.commons.lang3.StringUtils;
56

67
import java.util.List;
78

@@ -12,15 +13,17 @@ public class TodoMvcAppPage {
1213
private final Locator todoItems;
1314
private final Locator todoField;
1415

16+
private final String baseUrl;
17+
1518
public TodoMvcAppPage(Page page) {
1619
this.page = page;
17-
20+
baseUrl = (StringUtils.isEmpty(System.getenv("APP_HOST_URL"))) ? "http://localhost:7002" : System.getenv("APP_HOST_URL");
1821
this.todoItems = page.getByTestId("todo-item");
1922
this.todoField = page.getByTestId("text-input");
2023
}
2124

2225
public void open() {
23-
page.navigate("http://localhost:7002");
26+
page.navigate(baseUrl);
2427
}
2528

2629
public List<String> todoItemsDisplayed() {

0 commit comments

Comments
 (0)