|
14 | 14 | import io.github.easy4j.opencli.browser.result.OpenCliBrowserSourceComparison; |
15 | 15 | import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab; |
16 | 16 | import io.github.easy4j.opencli.browser.support.OpenCliBrowserFindOptions; |
| 17 | +import io.github.easy4j.opencli.browser.support.OpenCliBrowserTabOptions; |
| 18 | +import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException; |
17 | 19 | import io.github.easy4j.opencli.browser.support.OpenCliBrowserSnapshotSource; |
18 | 20 | import java.net.URI; |
19 | 21 | import java.util.Collections; |
|
24 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; |
25 | 27 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
26 | 28 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
27 | 30 |
|
28 | 31 | /** Opt-in verification against an externally provisioned disposable Browser Bridge. */ |
29 | 32 | class OpenCliBrowserBridgeIT { |
@@ -86,6 +89,35 @@ void queryAndCaptureUseTheRealBridgeResponses() { |
86 | 89 | } |
87 | 90 | } |
88 | 91 |
|
| 92 | + @Test |
| 93 | + void boundTabSurvivesTypedSuccessFailureAndClientShutdown() { |
| 94 | + String url = URI.create(fixtureUrl()).resolve("/bound-fixture.html").toString(); |
| 95 | + String pageId; |
| 96 | + try (OpenCliClient client = new OpenCliClient(properties())) { |
| 97 | + OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-bound-fixture", null); |
| 98 | + session.bind(); |
| 99 | + pageId = boundPage(session, url).getPageId(); |
| 100 | + assertEquals(url, parsed(session.snapshotTyped(null, OpenCliBrowserSnapshotSource.DOM)).getUrl()); |
| 101 | + |
| 102 | + OpenCliBrowserTabOptions missing = OpenCliBrowserTabOptions.builder().tab("missing-fixture-page").build(); |
| 103 | + OpenCliNonZeroExitException failure = assertThrows(OpenCliNonZeroExitException.class, |
| 104 | + () -> session.snapshotTyped(missing, OpenCliBrowserSnapshotSource.DOM)); |
| 105 | + assertNotNull(failure.getPartialResult()); |
| 106 | + assertEquals(pageId, boundPage(session, url).getPageId()); |
| 107 | + } |
| 108 | + try (OpenCliClient client = new OpenCliClient(properties())) { |
| 109 | + OpenCliBrowserSession session = new OpenCliBrowserSession(client.getExecutor(), "sdk-bound-fixture", null); |
| 110 | + assertEquals(pageId, boundPage(session, url).getPageId()); |
| 111 | + session.unbind(); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + private static OpenCliBrowserTab boundPage(OpenCliBrowserSession session, String url) { |
| 116 | + return parsed(session.tabListTyped()).stream() |
| 117 | + .filter(tab -> url.equals(tab.getUrl())).findFirst() |
| 118 | + .orElseThrow(() -> new AssertionError("The original bound tab must remain open")); |
| 119 | + } |
| 120 | + |
89 | 121 | private static OpenCliProperties properties() { |
90 | 122 | OpenCliProperties properties = new OpenCliProperties(); |
91 | 123 | properties.setExecutable(requiredEnvironment("OPENCLI_INSTALLED_NODE")); |
|
0 commit comments