2020import static org .openqa .selenium .testing .Safely .safelyCall ;
2121import static org .openqa .selenium .testing .drivers .Browser .CHROME ;
2222import static org .openqa .selenium .testing .drivers .Browser .EDGE ;
23+ import static org .openqa .selenium .testing .drivers .Browser .FIREFOX ;
2324import static org .openqa .selenium .testing .drivers .Browser .IE ;
2425import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
2526
3334import org .junit .jupiter .api .BeforeEach ;
3435import org .junit .jupiter .api .Test ;
3536import org .openqa .selenium .bidi .Script ;
37+ import org .openqa .selenium .bidi .browsingcontext .BrowsingContext ;
3638import org .openqa .selenium .environment .webserver .AppServer ;
3739import org .openqa .selenium .environment .webserver .NettyAppServer ;
3840import org .openqa .selenium .testing .JupiterTestBase ;
3941import org .openqa .selenium .testing .NotYetImplemented ;
42+ import org .openqa .selenium .testing .Pages ;
4043
4144public class ScriptEventsTest extends JupiterTestBase {
4245 private AppServer server ;
@@ -52,7 +55,7 @@ public void setUp() {
5255 @ NotYetImplemented (IE )
5356 @ NotYetImplemented (EDGE )
5457 @ NotYetImplemented (CHROME )
55- void canAddPreloadScriptWithChannelOptions ()
58+ void canListenToChannelMessage ()
5659 throws ExecutionException , InterruptedException , TimeoutException {
5760 try (Script script = new Script (driver )) {
5861 CompletableFuture <Message > future = new CompletableFuture <>();
@@ -78,6 +81,47 @@ void canAddPreloadScriptWithChannelOptions()
7881 }
7982 }
8083
84+ @ Test
85+ @ NotYetImplemented (SAFARI )
86+ @ NotYetImplemented (IE )
87+ @ NotYetImplemented (EDGE )
88+ @ NotYetImplemented (CHROME )
89+ void canListenToRealmCreatedEvent ()
90+ throws ExecutionException , InterruptedException , TimeoutException {
91+ try (Script script = new Script (driver )) {
92+ CompletableFuture <RealmInfo > future = new CompletableFuture <>();
93+ script .onRealmCreated (future ::complete );
94+
95+ BrowsingContext context = new BrowsingContext (driver , driver .getWindowHandle ());
96+
97+ context .navigate (new Pages (server ).blankPage );
98+ RealmInfo realmInfo = future .get (5 , TimeUnit .SECONDS );
99+ assertThat (realmInfo .getRealmId ()).isNotNull ();
100+ assertThat (realmInfo .getRealmType ()).isEqualTo (RealmType .WINDOW );
101+ }
102+ }
103+
104+ @ Test
105+ @ NotYetImplemented (SAFARI )
106+ @ NotYetImplemented (IE )
107+ @ NotYetImplemented (EDGE )
108+ @ NotYetImplemented (CHROME )
109+ @ NotYetImplemented (FIREFOX )
110+ void canListenToRealmDestroyedEvent ()
111+ throws ExecutionException , InterruptedException , TimeoutException {
112+ try (Script script = new Script (driver )) {
113+ CompletableFuture <RealmInfo > future = new CompletableFuture <>();
114+ script .onRealmDestroyed (future ::complete );
115+
116+ BrowsingContext context = new BrowsingContext (driver , driver .getWindowHandle ());
117+
118+ context .close ();
119+ RealmInfo realmInfo = future .get (5 , TimeUnit .SECONDS );
120+ assertThat (realmInfo .getRealmId ()).isNotNull ();
121+ assertThat (realmInfo .getRealmType ()).isEqualTo (RealmType .WINDOW );
122+ }
123+ }
124+
81125 @ AfterEach
82126 public void quitDriver () {
83127 if (driver != null ) {
0 commit comments