Skip to content

Commit a608383

Browse files
committed
Add golden master test
1 parent 4fe3cb0 commit a608383

4 files changed

Lines changed: 341 additions & 4 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"streetsidesoftware.code-spell-checker"
2626
]
2727
}
28-
}
28+
},
29+
"forwardPorts": 4000
2930
}
30-

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ um in die Datenbank zu schauen.
2929

3030
## Aufgabe
3131

32-
Navigieren Sie zum Warenkorb und schauen Sie sich dann den Inhalt der Tabelle `tab_order` an.
33-
Navigieren Sie durch den Checkout-Prozess und sehen Sie, wie sich der Inhalt der Tabelle ändert.
32+
Die Datei `CheckoutTest` im Ordner
33+
`golden-master-tests/src/test/java/de/openknowledge/sample/onlineshop/test`
34+
enthält einen UI-Test mit dem Framework Playwright.
35+
Führen Sie den Test aus und schauen Sie, dass er grün ist.
36+
Überlegen Sie, welche weiteren Pfade durch den Bestellabschluss es geben könnte.
37+
Schreiben Sie Tests für diese Fälle.
38+
Schreiben Sie auch Tests für das Pflegen der Adressen in der Kundenverwaltung.

golden-master-tests/pom.xml

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- ~ Copyright (C) open knowledge GmbH. ~ ~ Licensed under the Apache License,
3+
Version 2.0 (the "License"); you may not use this file except in compliance
4+
with ~ the License. You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0
5+
~ ~ Unless required by applicable law or agreed to in writing, software distributed
6+
under the License is distributed on ~ an "AS IS" BASIS, WITHOUT WARRANTIES
7+
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
8+
the ~ specific language governing permissions and limitations under the License. -->
9+
10+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<groupId>de.openkonwledge.sample.shop</groupId>
15+
<artifactId>golden-master-tests</artifactId>
16+
<version>1.0.0-SNAPSHOT</version>
17+
<packaging>jar</packaging>
18+
19+
<properties>
20+
<service.name>online-shop</service.name>
21+
<maven.compiler.source>17</maven.compiler.source>
22+
<maven.compiler.target>17</maven.compiler.target>
23+
<failOnMissingWebXml>false</failOnMissingWebXml>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
<meecrowave.version>1.2.13</meecrowave.version>
26+
<junit.version>5.8.2</junit.version>
27+
</properties>
28+
29+
<dependencies>
30+
31+
<dependency>
32+
<groupId>org.apache.meecrowave</groupId>
33+
<artifactId>meecrowave-specs-api</artifactId>
34+
<version>${meecrowave.version}</version>
35+
<scope>provided</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.apache.meecrowave</groupId>
39+
<artifactId>meecrowave-core</artifactId>
40+
<version>${meecrowave.version}</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.thymeleaf</groupId>
45+
<artifactId>thymeleaf</artifactId>
46+
<version>3.0.14.RELEASE</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.apache.geronimo.specs</groupId>
50+
<artifactId>geronimo-validation_2.0_spec</artifactId>
51+
<version>1.0</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.apache.bval</groupId>
55+
<artifactId>bval-jsr</artifactId>
56+
<version>2.0.6</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.eclipse.microprofile.config</groupId>
60+
<artifactId>microprofile-config-api</artifactId>
61+
<version>1.3</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.apache.geronimo.config</groupId>
65+
<artifactId>geronimo-config-impl</artifactId>
66+
<version>1.2.2</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.eclipse.microprofile.openapi</groupId>
70+
<artifactId>microprofile-openapi-api</artifactId>
71+
<version>1.1.2</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.apache.geronimo</groupId>
75+
<artifactId>geronimo-openapi-impl</artifactId>
76+
<version>1.0.12</version>
77+
<scope>runtime</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.webjars</groupId>
81+
<artifactId>swagger-ui</artifactId>
82+
<version>5.4.2</version>
83+
<scope>runtime</scope>
84+
</dependency>
85+
86+
<dependency>
87+
<groupId>org.apache.commons</groupId>
88+
<artifactId>commons-lang3</artifactId>
89+
<version>3.9</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.apache.commons</groupId>
93+
<artifactId>commons-io</artifactId>
94+
<version>1.3.2</version>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.hibernate.orm</groupId>
98+
<artifactId>hibernate-core</artifactId>
99+
<version>6.4.0.Final</version>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.slf4j</groupId>
103+
<artifactId>slf4j-simple</artifactId>
104+
<version>1.7.25</version>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.postgresql</groupId>
108+
<artifactId>postgresql</artifactId>
109+
<version>42.7.0</version>
110+
</dependency>
111+
112+
<dependency>
113+
<groupId>org.junit.jupiter</groupId>
114+
<artifactId>junit-jupiter-api</artifactId>
115+
<version>${junit.version}</version>
116+
<scope>test</scope>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.junit.jupiter</groupId>
120+
<artifactId>junit-jupiter-engine</artifactId>
121+
<version>${junit.version}</version>
122+
<scope>test</scope>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.assertj</groupId>
126+
<artifactId>assertj-core</artifactId>
127+
<version>3.22.0</version>
128+
<scope>test</scope>
129+
</dependency>
130+
<dependency>
131+
<groupId>com.microsoft.playwright</groupId>
132+
<artifactId>playwright</artifactId>
133+
<version>1.44.0</version>
134+
<scope>test</scope>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.apache.meecrowave</groupId>
138+
<artifactId>meecrowave-junit</artifactId>
139+
<version>${meecrowave.version}</version>
140+
<scope>test</scope>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.testcontainers</groupId>
144+
<artifactId>junit-jupiter</artifactId>
145+
<version>1.19.8</version>
146+
<scope>test</scope>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.testcontainers</groupId>
150+
<artifactId>postgresql</artifactId>
151+
<version>1.19.8</version>
152+
<scope>test</scope>
153+
</dependency>
154+
<dependency>
155+
<groupId>org.testcontainers</groupId>
156+
<artifactId>testcontainers</artifactId>
157+
<version>1.19.8</version>
158+
<scope>test</scope>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.flywaydb</groupId>
162+
<artifactId>flyway-core</artifactId>
163+
<version>9.21.0</version>
164+
<scope>test</scope>
165+
</dependency>
166+
<dependency>
167+
<groupId>au.com.dius.pact.consumer</groupId>
168+
<artifactId>junit5</artifactId>
169+
<version>4.3.15</version>
170+
<scope>test</scope>
171+
</dependency>
172+
<dependency>
173+
<groupId>au.com.dius.pact.provider</groupId>
174+
<artifactId>junit5</artifactId>
175+
<version>4.3.15</version>
176+
<scope>test</scope>
177+
</dependency>
178+
</dependencies>
179+
<build>
180+
<finalName>${project.artifactId}</finalName>
181+
<plugins>
182+
<plugin>
183+
<groupId>org.apache.maven.plugins</groupId>
184+
<artifactId>maven-surefire-plugin</artifactId>
185+
<version>3.1.2</version>
186+
<configuration>
187+
<systemPropertyVariables>
188+
<org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy>false</org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy>
189+
</systemPropertyVariables>
190+
</configuration>
191+
</plugin>
192+
<plugin>
193+
<groupId>org.apache.maven.plugins</groupId>
194+
<artifactId>maven-war-plugin</artifactId>
195+
<version>3.4.0</version>
196+
</plugin>
197+
<plugin>
198+
<groupId>org.apache.maven.plugins</groupId>
199+
<artifactId>maven-dependency-plugin</artifactId>
200+
<version>3.6.1</version>
201+
<executions>
202+
<execution>
203+
<id>copy-runner</id>
204+
<phase>package</phase>
205+
<goals>
206+
<goal>copy</goal>
207+
</goals>
208+
<configuration>
209+
<artifactItems>
210+
<artifactItem>
211+
<groupId>org.apache.meecrowave</groupId>
212+
<artifactId>meecrowave-core</artifactId>
213+
<version>${meecrowave-version}</version>
214+
<classifier>runner</classifier>
215+
</artifactItem>
216+
</artifactItems>
217+
<outputDirectory>${project.build.directory}/runner</outputDirectory>
218+
<stripVersion>true</stripVersion>
219+
</configuration>
220+
</execution>
221+
</executions>
222+
</plugin>
223+
</plugins>
224+
</build>
225+
</project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (C) open knowledge GmbH.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.openknowledge.sample.onlineshop.test;
17+
18+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
19+
20+
import java.io.File;
21+
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.testcontainers.containers.ComposeContainer;
28+
import org.testcontainers.containers.wait.strategy.Wait;
29+
30+
import com.microsoft.playwright.Browser;
31+
import com.microsoft.playwright.BrowserContext;
32+
import com.microsoft.playwright.Locator;
33+
import com.microsoft.playwright.Page;
34+
import com.microsoft.playwright.Playwright;
35+
36+
public class CheckoutTest {
37+
38+
private static final int ONLINE_SHOP_PORT = 8080;
39+
private static ComposeContainer environment =
40+
new ComposeContainer(new File("../docker-compose.yaml"))
41+
.withExposedService("online-shop-1", ONLINE_SHOP_PORT, Wait.forHttp("/index.html").forStatusCode(200));
42+
private static String onlineshopUrl;
43+
private static Playwright playwright;
44+
private static Browser browser;
45+
46+
private BrowserContext context;
47+
private Page page;
48+
49+
@BeforeAll
50+
static void launchBrowser() {
51+
environment.start();
52+
onlineshopUrl = "http://" + environment.getServiceHost("online-shop_1", ONLINE_SHOP_PORT) + ":" + environment.getServicePort("online-shop-1", ONLINE_SHOP_PORT);
53+
playwright = Playwright.create();
54+
browser = playwright.chromium().launch();
55+
}
56+
57+
@AfterAll
58+
static void closeBrowser() {
59+
playwright.close();
60+
environment.close();
61+
}
62+
63+
@BeforeEach
64+
void createContextAndPage() {
65+
context = browser.newContext();
66+
page = context.newPage();
67+
}
68+
69+
@AfterEach
70+
void closeContext() {
71+
context.close();
72+
}
73+
74+
@Test
75+
void shouldCheckout() {
76+
page.navigate(onlineshopUrl + "/index.html");
77+
Locator caption = page.getByText("Onlineshop");
78+
assertThat(caption).isVisible();
79+
80+
Locator addToCartButton = page.getByText("In den Warenkorb");
81+
assertThat(addToCartButton.first()).isVisible();
82+
addToCartButton.first().click();
83+
84+
Locator checkoutButton = page.getByText("Zur Kasse gehen");
85+
page.waitForCondition(() -> checkoutButton.isVisible());
86+
checkoutButton.click();
87+
88+
Locator payByEmailButton = page.getByText("Email-Bezahlung");
89+
page.waitForCondition(() -> payByEmailButton.isVisible());
90+
payByEmailButton.click();
91+
Locator emailInput = page.locator("#email");
92+
page.waitForCondition(() -> emailInput.isVisible());
93+
emailInput.fill("max.mustermann@openknowledge.de");
94+
page.getByText("Auswählen").last().click();
95+
96+
page.waitForCondition(() -> page.getByText("Rechnungsadresse").isVisible());
97+
page.getByText("Auswählen").first().click();
98+
99+
page.waitForCondition(() -> page.getByText("Lieferadresse").isVisible());
100+
page.getByText("Aus Rechnungsadresse übernehmen").click();
101+
102+
page.waitForCondition(() -> page.getByText("Kostenpflichtig Bestellen").isVisible());
103+
page.getByText("Kostenpflichtig Bestellen").click();
104+
105+
page.waitForCondition(() -> page.getByText("Bestellung erfolgreich abgeschlossen.").isVisible());
106+
}
107+
}

0 commit comments

Comments
 (0)