Skip to content

Commit fa658f4

Browse files
committed
[bidi] Add browsing context destroyed event
1 parent 8383860 commit fa658f4

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

java/src/org/openqa/selenium/bidi/BrowsingContextInspector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void onBrowsingContextCreated(Consumer<BrowsingContextInfo> consumer) {
113113
}
114114
}
115115

116-
private void onBrowsingContextDestroyed(Consumer<BrowsingContextInfo> consumer) {
116+
public void onBrowsingContextDestroyed(Consumer<BrowsingContextInfo> consumer) {
117117
if (browsingContextIds.isEmpty()) {
118118
this.bidi.addListener(browsingContextDestroyed, consumer);
119119
} else {

java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ void canListenToWindowBrowsingContextCreatedEvent()
7373
}
7474
}
7575

76+
@Test
77+
@NotYetImplemented(SAFARI)
78+
@NotYetImplemented(IE)
79+
@NotYetImplemented(CHROME)
80+
@NotYetImplemented(EDGE)
81+
void canListenToBrowsingContextDestroyedEvent()
82+
throws ExecutionException, InterruptedException, TimeoutException {
83+
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
84+
CompletableFuture<BrowsingContextInfo> future = new CompletableFuture<>();
85+
86+
inspector.onBrowsingContextDestroyed(future::complete);
87+
88+
String windowHandle = driver.switchTo().newWindow(WindowType.WINDOW).getWindowHandle();
89+
90+
driver.close();
91+
92+
BrowsingContextInfo browsingContextInfo = future.get(5, TimeUnit.SECONDS);
93+
94+
assertThat(browsingContextInfo.getId()).isEqualTo(windowHandle);
95+
assertThat("about:blank").isEqualTo(browsingContextInfo.getUrl());
96+
assertThat(browsingContextInfo.getChildren()).isEqualTo(null);
97+
assertThat(browsingContextInfo.getParentBrowsingContext()).isEqualTo(null);
98+
}
99+
}
100+
76101
@Test
77102
@NotYetImplemented(SAFARI)
78103
@NotYetImplemented(IE)

javascript/node/selenium-webdriver/bidi/browsingContextInspector.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class BrowsingContextInspector {
3737
)
3838
}
3939

40+
async onBrowsingContextDestroyed(callback) {
41+
await this.subscribeAndHandleEvent(
42+
'browsingContext.contextDestroyed',
43+
callback
44+
)
45+
}
46+
4047
async onNavigationStarted(callback) {
4148
await this.subscribeAndHandleEvent(
4249
'browsingContext.navigationStarted',

javascript/node/selenium-webdriver/test/bidi/browsingcontext_inspector_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ suite(
5656
assert.equal(contextInfo.parentBrowsingContext, null)
5757
})
5858

59+
it('can listen to browsing context destroyed event', async function () {
60+
let contextInfo = null
61+
const browsingcontextInspector = await BrowsingContextInspector(driver)
62+
await browsingcontextInspector.onBrowsingContextDestroyed((entry) => {
63+
contextInfo = entry
64+
})
65+
66+
await driver.switchTo().newWindow('window')
67+
68+
const windowHandle = await driver.getWindowHandle()
69+
await driver.close()
70+
71+
assert.equal(contextInfo.id, windowHandle)
72+
assert.equal(contextInfo.url, 'about:blank')
73+
assert.equal(contextInfo.children, null)
74+
assert.equal(contextInfo.parentBrowsingContext, null)
75+
})
76+
5977
it('can listen to tab browsing context created event', async function () {
6078
let contextInfo = null
6179
const browsingcontextInspector = await BrowsingContextInspector(driver)

0 commit comments

Comments
 (0)