20
20
import static org .openqa .selenium .testing .Safely .safelyCall ;
21
21
import static org .openqa .selenium .testing .drivers .Browser .CHROME ;
22
22
import static org .openqa .selenium .testing .drivers .Browser .EDGE ;
23
+ import static org .openqa .selenium .testing .drivers .Browser .FIREFOX ;
23
24
import static org .openqa .selenium .testing .drivers .Browser .IE ;
24
25
import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
25
26
33
34
import org .junit .jupiter .api .BeforeEach ;
34
35
import org .junit .jupiter .api .Test ;
35
36
import org .openqa .selenium .bidi .Script ;
37
+ import org .openqa .selenium .bidi .browsingcontext .BrowsingContext ;
36
38
import org .openqa .selenium .environment .webserver .AppServer ;
37
39
import org .openqa .selenium .environment .webserver .NettyAppServer ;
38
40
import org .openqa .selenium .testing .JupiterTestBase ;
39
41
import org .openqa .selenium .testing .NotYetImplemented ;
42
+ import org .openqa .selenium .testing .Pages ;
40
43
41
44
public class ScriptEventsTest extends JupiterTestBase {
42
45
private AppServer server ;
@@ -52,7 +55,7 @@ public void setUp() {
52
55
@ NotYetImplemented (IE )
53
56
@ NotYetImplemented (EDGE )
54
57
@ NotYetImplemented (CHROME )
55
- void canAddPreloadScriptWithChannelOptions ()
58
+ void canListenToChannelMessage ()
56
59
throws ExecutionException , InterruptedException , TimeoutException {
57
60
try (Script script = new Script (driver )) {
58
61
CompletableFuture <Message > future = new CompletableFuture <>();
@@ -78,6 +81,47 @@ void canAddPreloadScriptWithChannelOptions()
78
81
}
79
82
}
80
83
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
+
81
125
@ AfterEach
82
126
public void quitDriver () {
83
127
if (driver != null ) {
0 commit comments