-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUiTest.java
More file actions
65 lines (56 loc) · 2.23 KB
/
UiTest.java
File metadata and controls
65 lines (56 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package app.ui;
import app.App;
import app.ui.support.ChromeContainer;
import app.ui.support.ContainerDriverProvider;
import io.karatelabs.core.Runner;
import io.karatelabs.core.SuiteResult;
import io.karatelabs.http.HttpServer;
import io.karatelabs.http.ServerConfig;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class UiTest {
// Fixed port: Testcontainers.exposeHostPorts(...) must run before the app starts,
// so we can't pick a random port after the server binds.
private static final int PORT = 18080;
static {
// Docker 29.x API version negotiation workaround.
// https://github.com/testcontainers/testcontainers-java/issues/11212
System.setProperty("api.version", "1.44");
}
static HttpServer server;
static ChromeContainer chrome;
@BeforeAll
static void beforeAll() {
ServerConfig config = App.serverConfig("src/main/java/app");
server = App.start(config, PORT);
chrome = new ChromeContainer();
chrome.start();
}
@AfterAll
static void afterAll() {
if (chrome != null) {
chrome.stop();
}
if (server != null) {
server.stopAndWait();
}
}
@Test
void testAll() {
ContainerDriverProvider provider = new ContainerDriverProvider(chrome);
// One hybrid suite: api + ui features in a single report. Same in-process
// app serves both — karate HTTP hits localhost, the browser (in the
// container) hits host.docker.internal.
SuiteResult result = Runner.path("classpath:app/api", "classpath:app/ui")
// @external: features that hit external hosts (google, httpbin, ...).
// @todo: features awaiting a karate-js fix (see TODO headers).
.tags("~@external", "~@todo")
.systemProperty("serverUrl", chrome.getHostAccessUrl(PORT))
.systemProperty("apiUrl", "http://localhost:" + PORT)
.driverProvider(provider)
.parallel(3);
assertEquals(0, result.getScenarioFailedCount(), String.join("\n", result.getErrors()));
}
}