1
+ import org.hildan.chrome.devtools.protocol.ChromeDPTarget
2
+ import org.junit.jupiter.api.Test
1
3
import org.testcontainers.containers.*
2
4
import org.testcontainers.junit.jupiter.*
3
5
import org.testcontainers.junit.jupiter.Container
4
6
import org.testcontainers.utility.*
5
7
import kotlin.test.Ignore
8
+ import kotlin.test.assertEquals
9
+ import kotlin.test.assertTrue
6
10
7
11
@Testcontainers
8
12
class ZenikaIntegrationTests : LocalIntegrationTestBase () {
@@ -22,10 +26,65 @@ class ZenikaIntegrationTests : LocalIntegrationTestBase() {
22
26
override val httpUrl: String
23
27
get() = " http://localhost:${zenikaChrome.firstMappedPort} "
24
28
29
+ // the WS URL is not known in advance and needs to be queried first via the HTTP API, hence the HTTP URL here
25
30
override val wsConnectUrl: String
26
31
get() = " http://localhost:${zenikaChrome.firstMappedPort} "
27
32
28
33
@Ignore(" The Zenika container seems out of data and still treats cookiePartitionKey as a string instead of object" )
29
34
override fun missingExpiresInCookie () {
30
35
}
36
+
37
+ @Suppress(" DEPRECATION" ) // the point is to test this deprecated API
38
+ @Test
39
+ fun httpTabEndpoints_basic () {
40
+ runBlockingWithTimeout {
41
+ val chrome = chromeHttp()
42
+ val originalTabCount = chrome.targets().size
43
+
44
+ val newTab = chrome.newTab()
45
+ assertEquals(" about:blank" , newTab.url.trimEnd(' /' ))
46
+ assertTargetCount(originalTabCount + 1 , chrome.targets())
47
+ chrome.closeTab(newTab.id)
48
+
49
+ assertTargetCount(originalTabCount, chrome.targets())
50
+ chrome.newTab()
51
+ chrome.newTab()
52
+ chrome.closeAllTargets()
53
+ assertTargetCount(0 , chrome.targets())
54
+ }
55
+ }
56
+
57
+ @Suppress(" DEPRECATION" ) // the point is to test this deprecated API
58
+ @Test
59
+ fun httpTabEndpoints_newTabWithCustomUrl () {
60
+ runBlockingWithTimeout {
61
+ val chrome = chromeHttp()
62
+
63
+ val googleTab = chrome.newTab(url = " https://www.google.com" )
64
+ assertEquals(" https://www.google.com" , googleTab.url.trimEnd(' /' ))
65
+
66
+ val targets = chrome.targets()
67
+ assertTrue(
68
+ actual = targets.any { it.url.trimEnd(' /' ) == " https://www.google.com" },
69
+ message = " the google.com page target should be listed, got:\n ${targets.joinToString(" \n " )} " ,
70
+ )
71
+
72
+ chrome.closeTab(googleTab.id)
73
+
74
+ val targetsAfterClose = chrome.targets()
75
+ assertTrue(
76
+ actual = targetsAfterClose.none { it.url.trimEnd(' /' ) == " https://www.google.com" },
77
+ message = " the google.com page target should be closed, got:\n ${targetsAfterClose.joinToString(" \n " )} " ,
78
+ )
79
+ }
80
+ }
81
+
82
+ private fun assertTargetCount (expected : Int , currentTargets : List <ChromeDPTarget >) {
83
+ assertEquals(
84
+ expected = expected,
85
+ actual = currentTargets.size,
86
+ message = " Expected $expected tab(s) but got ${currentTargets.size} instead:\n " +
87
+ currentTargets.joinToString(" \n " ),
88
+ )
89
+ }
31
90
}
0 commit comments