File tree 3 files changed +57
-0
lines changed
src/org/openqa/selenium/remote
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -121,4 +121,14 @@ public long addDomMutationHandler(Consumer<DomMutation> consumer) {
121
121
public void removeDomMutationHandler (long id ) {
122
122
this .biDi .removeListener (id );
123
123
}
124
+
125
+ @ Override
126
+ public String pin (String script ) {
127
+ return this .script .addPreloadScript (script );
128
+ }
129
+
130
+ @ Override
131
+ public void unpin (String id ) {
132
+ this .script .removePreloadScript (id );
133
+ }
124
134
}
Original file line number Diff line number Diff line change @@ -36,4 +36,8 @@ public interface Script {
36
36
long addDomMutationHandler (Consumer <DomMutation > event );
37
37
38
38
void removeDomMutationHandler (long id );
39
+
40
+ String pin (String script );
41
+
42
+ void unpin (String id );
39
43
}
Original file line number Diff line number Diff line change @@ -245,4 +245,47 @@ void canRemoveDomMutationHandler() throws InterruptedException {
245
245
246
246
Assertions .assertThat (latch .await (10 , SECONDS )).isFalse ();
247
247
}
248
+
249
+ @ Test
250
+ void canPinScript () throws ExecutionException , InterruptedException , TimeoutException {
251
+ CompletableFuture <ConsoleLogEntry > future = new CompletableFuture <>();
252
+
253
+ ((RemoteWebDriver ) driver ).script ().pin ("() => { console.log('Hello!'); }" );
254
+
255
+ long id = ((RemoteWebDriver ) driver ).script ().addConsoleMessageHandler (future ::complete );
256
+
257
+ page = server .whereIs ("/bidi/logEntryAdded.html" );
258
+ driver .get (page );
259
+
260
+ ConsoleLogEntry logEntry = future .get (5 , TimeUnit .SECONDS );
261
+
262
+ assertThat (logEntry .getText ()).isEqualTo ("Hello!" );
263
+
264
+ ((RemoteWebDriver ) driver ).script ().removeConsoleMessageHandler (id );
265
+ }
266
+
267
+ @ Test
268
+ void canUnpinScript () throws ExecutionException , InterruptedException , TimeoutException {
269
+ CountDownLatch latch = new CountDownLatch (2 );
270
+
271
+ String pinnedScript =
272
+ ((RemoteWebDriver ) driver ).script ().pin ("() => { console.log('Hello!'); }" );
273
+
274
+ long id =
275
+ ((RemoteWebDriver ) driver )
276
+ .script ()
277
+ .addConsoleMessageHandler (consoleLogEntry -> latch .countDown ());
278
+
279
+ page = server .whereIs ("/bidi/logEntryAdded.html" );
280
+
281
+ driver .get (page );
282
+
283
+ ((RemoteWebDriver ) driver ).script ().unpin (pinnedScript );
284
+
285
+ driver .get (page );
286
+
287
+ assertThat (latch .getCount ()).isEqualTo (1L );
288
+
289
+ ((RemoteWebDriver ) driver ).script ().removeConsoleMessageHandler (id );
290
+ }
248
291
}
You can’t perform that action at this time.
0 commit comments