|
9 | 9 |
|
10 | 10 | import java.io.IOException;
|
11 | 11 | import java.nio.charset.StandardCharsets;
|
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.List; |
12 | 14 | import java.util.concurrent.ExecutionException;
|
13 | 15 | import java.util.concurrent.Future;
|
14 | 16 | import java.util.regex.Pattern;
|
@@ -349,4 +351,44 @@ public void shouldWorkWithBaseURL(Browser browser) throws Exception {
|
349 | 351 | asList("open", "message: data=echo origin=ws://localhost:" + webSocketServer.getPort() + " lastEventId="),
|
350 | 352 | newPage.evaluate("window.log"));
|
351 | 353 | }
|
| 354 | + |
| 355 | + @Test |
| 356 | + public void shouldWorkWithNoTrailingSlash(Page page) throws Exception { |
| 357 | + List<String> log = new ArrayList<>(); |
| 358 | + |
| 359 | + // No trailing slash in the route pattern |
| 360 | + page.routeWebSocket("ws://localhost:" + webSocketServer.getPort(), ws -> { |
| 361 | + ws.onMessage(message -> { |
| 362 | + log.add(message.text()); |
| 363 | + ws.send("response"); |
| 364 | + }); |
| 365 | + }); |
| 366 | + |
| 367 | + page.navigate("about:blank"); |
| 368 | + page.evaluate("({ port }) => {\n" + |
| 369 | + " window.log = [];\n" + |
| 370 | + " // No trailing slash in WebSocket URL\n" + |
| 371 | + " window.ws = new WebSocket('ws://localhost:' + port);\n" + |
| 372 | + " window.ws.addEventListener('message', event => window.log.push(event.data));\n" + |
| 373 | + "}", mapOf("port", webSocketServer.getPort())); |
| 374 | + |
| 375 | + // Wait for WebSocket to be ready (readyState === 1) |
| 376 | + page.waitForCondition(() -> { |
| 377 | + Integer result = (Integer) page.evaluate("() => window.ws.readyState"); |
| 378 | + return result == 1; |
| 379 | + }); |
| 380 | + |
| 381 | + page.evaluate("() => window.ws.send('query')"); |
| 382 | + |
| 383 | + // Wait and verify server received message |
| 384 | + page.waitForCondition(() -> log.size() >= 1); |
| 385 | + assertEquals(asList("query"), log); |
| 386 | + |
| 387 | + // Wait and verify client received response |
| 388 | + page.waitForCondition(() -> { |
| 389 | + Boolean result = (Boolean) page.evaluate("() => window.log.length >= 1"); |
| 390 | + return result; |
| 391 | + }); |
| 392 | + assertEquals(asList("response"), page.evaluate("window.log")); |
| 393 | + } |
352 | 394 | }
|
0 commit comments