@@ -150,15 +150,15 @@ def test_add_preload_script(driver, pages):
150150 """Test adding a preload script."""
151151 function_declaration = "() => { window.preloadExecuted = true; }"
152152
153- script_id = driver .script .add_preload_script (function_declaration )
153+ script_id = driver .script ._add_preload_script (function_declaration )
154154 assert script_id is not None
155155 assert isinstance (script_id , str )
156156
157157 # Navigate to a page to trigger the preload script
158158 pages .load ("blank.html" )
159159
160160 # Check if the preload script was executed
161- result = driver .script .evaluate (
161+ result = driver .script ._evaluate (
162162 "window.preloadExecuted" , {"context" : driver .current_window_handle }, await_promise = False
163163 )
164164 assert result .result ["value" ] is True
@@ -170,12 +170,12 @@ def test_add_preload_script_with_arguments(driver, pages):
170170
171171 arguments = [{"type" : "channel" , "value" : {"channel" : "test-channel" , "ownership" : "root" }}]
172172
173- script_id = driver .script .add_preload_script (function_declaration , arguments = arguments )
173+ script_id = driver .script ._add_preload_script (function_declaration , arguments = arguments )
174174 assert script_id is not None
175175
176176 pages .load ("blank.html" )
177177
178- result = driver .script .evaluate (
178+ result = driver .script ._evaluate (
179179 "window.preloadValue" , {"context" : driver .current_window_handle }, await_promise = False
180180 )
181181 assert result .result ["value" ] == "received"
@@ -186,12 +186,12 @@ def test_add_preload_script_with_contexts(driver, pages):
186186 function_declaration = "() => { window.contextSpecific = true; }"
187187 contexts = [driver .current_window_handle ]
188188
189- script_id = driver .script .add_preload_script (function_declaration , contexts = contexts )
189+ script_id = driver .script ._add_preload_script (function_declaration , contexts = contexts )
190190 assert script_id is not None
191191
192192 pages .load ("blank.html" )
193193
194- result = driver .script .evaluate (
194+ result = driver .script ._evaluate (
195195 "window.contextSpecific" , {"context" : driver .current_window_handle }, await_promise = False
196196 )
197197 assert result .result ["value" ] is True
@@ -207,12 +207,12 @@ def test_add_preload_script_with_user_contexts(driver, pages):
207207
208208 user_contexts = [user_context ]
209209
210- script_id = driver .script .add_preload_script (function_declaration , user_contexts = user_contexts )
210+ script_id = driver .script ._add_preload_script (function_declaration , user_contexts = user_contexts )
211211 assert script_id is not None
212212
213213 pages .load ("blank.html" )
214214
215- result = driver .script .evaluate (
215+ result = driver .script ._evaluate (
216216 "window.contextSpecific" , {"context" : driver .current_window_handle }, await_promise = False
217217 )
218218 assert result .result ["value" ] is True
@@ -222,19 +222,19 @@ def test_add_preload_script_with_sandbox(driver, pages):
222222 """Test adding a preload script with sandbox."""
223223 function_declaration = "() => { window.sandboxScript = true; }"
224224
225- script_id = driver .script .add_preload_script (function_declaration , sandbox = "test-sandbox" )
225+ script_id = driver .script ._add_preload_script (function_declaration , sandbox = "test-sandbox" )
226226 assert script_id is not None
227227
228228 pages .load ("blank.html" )
229229
230230 # calling evaluate without sandbox should return undefined
231- result = driver .script .evaluate (
231+ result = driver .script ._evaluate (
232232 "window.sandboxScript" , {"context" : driver .current_window_handle }, await_promise = False
233233 )
234234 assert result .result ["type" ] == "undefined"
235235
236236 # calling evaluate within the sandbox should return True
237- result = driver .script .evaluate (
237+ result = driver .script ._evaluate (
238238 "window.sandboxScript" ,
239239 {"context" : driver .current_window_handle , "sandbox" : "test-sandbox" },
240240 await_promise = False ,
@@ -247,21 +247,21 @@ def test_add_preload_script_invalid_arguments(driver):
247247 function_declaration = "() => {}"
248248
249249 with pytest .raises (ValueError , match = "Cannot specify both contexts and user_contexts" ):
250- driver .script .add_preload_script (function_declaration , contexts = ["context1" ], user_contexts = ["user1" ])
250+ driver .script ._add_preload_script (function_declaration , contexts = ["context1" ], user_contexts = ["user1" ])
251251
252252
253253def test_remove_preload_script (driver , pages ):
254254 """Test removing a preload script."""
255255 function_declaration = "() => { window.removableScript = true; }"
256256
257- script_id = driver .script .add_preload_script (function_declaration )
258- driver .script .remove_preload_script (script_id = script_id )
257+ script_id = driver .script ._add_preload_script (function_declaration )
258+ driver .script ._remove_preload_script (script_id = script_id )
259259
260260 # Navigate to a page after removing the script
261261 pages .load ("blank.html" )
262262
263263 # The script should not have executed
264- result = driver .script .evaluate (
264+ result = driver .script ._evaluate (
265265 "typeof window.removableScript" , {"context" : driver .current_window_handle }, await_promise = False
266266 )
267267 assert result .result ["value" ] == "undefined"
@@ -271,7 +271,7 @@ def test_evaluate_expression(driver, pages):
271271 """Test evaluating a simple expression."""
272272 pages .load ("blank.html" )
273273
274- result = driver .script .evaluate ("1 + 2" , {"context" : driver .current_window_handle }, await_promise = False )
274+ result = driver .script ._evaluate ("1 + 2" , {"context" : driver .current_window_handle }, await_promise = False )
275275
276276 assert result .realm is not None
277277 assert result .result ["type" ] == "number"
@@ -283,7 +283,7 @@ def test_evaluate_with_await_promise(driver, pages):
283283 """Test evaluating an expression that returns a promise."""
284284 pages .load ("blank.html" )
285285
286- result = driver .script .evaluate (
286+ result = driver .script ._evaluate (
287287 "Promise.resolve(42)" , {"context" : driver .current_window_handle }, await_promise = True
288288 )
289289
@@ -295,7 +295,7 @@ def test_evaluate_with_exception(driver, pages):
295295 """Test evaluating an expression that throws an exception."""
296296 pages .load ("blank.html" )
297297
298- result = driver .script .evaluate (
298+ result = driver .script ._evaluate (
299299 "throw new Error('Test error')" , {"context" : driver .current_window_handle }, await_promise = False
300300 )
301301
@@ -308,7 +308,7 @@ def test_evaluate_with_result_ownership(driver, pages):
308308 pages .load ("blank.html" )
309309
310310 # Test with ROOT ownership
311- result = driver .script .evaluate (
311+ result = driver .script ._evaluate (
312312 "({ test: 'value' })" ,
313313 {"context" : driver .current_window_handle },
314314 await_promise = False ,
@@ -319,7 +319,7 @@ def test_evaluate_with_result_ownership(driver, pages):
319319 assert "handle" in result .result
320320
321321 # Test with NONE ownership
322- result = driver .script .evaluate (
322+ result = driver .script ._evaluate (
323323 "({ test: 'value' })" ,
324324 {"context" : driver .current_window_handle },
325325 await_promise = False ,
@@ -336,7 +336,7 @@ def test_evaluate_with_serialization_options(driver, pages):
336336
337337 serialization_options = {"maxDomDepth" : 2 , "maxObjectDepth" : 2 , "includeShadowTree" : "all" }
338338
339- result = driver .script .evaluate (
339+ result = driver .script ._evaluate (
340340 "document.body" ,
341341 {"context" : driver .current_window_handle },
342342 await_promise = False ,
@@ -354,7 +354,7 @@ def test_evaluate_with_user_activation(driver, pages):
354354 """Test evaluating with user activation."""
355355 pages .load ("blank.html" )
356356
357- result = driver .script .evaluate (
357+ result = driver .script ._evaluate (
358358 "navigator.userActivation ? navigator.userActivation.isActive : false" ,
359359 {"context" : driver .current_window_handle },
360360 await_promise = False ,
@@ -369,7 +369,7 @@ def test_call_function(driver, pages):
369369 """Test calling a function."""
370370 pages .load ("blank.html" )
371371
372- result = driver .script .call_function (
372+ result = driver .script ._call_function (
373373 "(a, b) => a + b" ,
374374 await_promise = False ,
375375 target = {"context" : driver .current_window_handle },
@@ -385,11 +385,11 @@ def test_call_function_with_this(driver, pages):
385385 pages .load ("blank.html" )
386386
387387 # First set up an object
388- driver .script .evaluate (
388+ driver .script ._evaluate (
389389 "window.testObj = { value: 10 }" , {"context" : driver .current_window_handle }, await_promise = False
390390 )
391391
392- result = driver .script .call_function (
392+ result = driver .script ._call_function (
393393 "function() { return this.value; }" ,
394394 await_promise = False ,
395395 target = {"context" : driver .current_window_handle },
@@ -404,7 +404,7 @@ def test_call_function_with_user_activation(driver, pages):
404404 """Test calling a function with user activation."""
405405 pages .load ("blank.html" )
406406
407- result = driver .script .call_function (
407+ result = driver .script ._call_function (
408408 "() => navigator.userActivation ? navigator.userActivation.isActive : false" ,
409409 await_promise = False ,
410410 target = {"context" : driver .current_window_handle },
@@ -421,7 +421,7 @@ def test_call_function_with_serialization_options(driver, pages):
421421
422422 serialization_options = {"maxDomDepth" : 2 , "maxObjectDepth" : 2 , "includeShadowTree" : "all" }
423423
424- result = driver .script .call_function (
424+ result = driver .script ._call_function (
425425 "() => document.body" ,
426426 await_promise = False ,
427427 target = {"context" : driver .current_window_handle },
@@ -440,7 +440,7 @@ def test_call_function_with_exception(driver, pages):
440440 """Test calling a function that throws an exception."""
441441 pages .load ("blank.html" )
442442
443- result = driver .script .call_function (
443+ result = driver .script ._call_function (
444444 "() => { throw new Error('Function error'); }" ,
445445 await_promise = False ,
446446 target = {"context" : driver .current_window_handle },
@@ -454,7 +454,7 @@ def test_call_function_with_await_promise(driver, pages):
454454 """Test calling a function that returns a promise."""
455455 pages .load ("blank.html" )
456456
457- result = driver .script .call_function (
457+ result = driver .script ._call_function (
458458 "() => Promise.resolve('async result')" , await_promise = True , target = {"context" : driver .current_window_handle }
459459 )
460460
@@ -467,10 +467,10 @@ def test_call_function_with_result_ownership(driver, pages):
467467 pages .load ("blank.html" )
468468
469469 # Call a function that returns an object with ownership "root"
470- result = driver .script .call_function (
470+ result = driver .script ._call_function (
471471 "function() { return { greet: 'Hi', number: 42 }; }" ,
472- target = {"context" : driver .current_window_handle },
473472 await_promise = False ,
473+ target = {"context" : driver .current_window_handle },
474474 result_ownership = "root" ,
475475 )
476476
@@ -480,10 +480,10 @@ def test_call_function_with_result_ownership(driver, pages):
480480 handle = result .result ["handle" ]
481481
482482 # Use the handle in another function call
483- result2 = driver .script .call_function (
483+ result2 = driver .script ._call_function (
484484 "function() { return this.number + 1; }" ,
485- target = {"context" : driver .current_window_handle },
486485 await_promise = False ,
486+ target = {"context" : driver .current_window_handle },
487487 this = {"handle" : handle },
488488 )
489489
@@ -495,7 +495,7 @@ def test_get_realms(driver, pages):
495495 """Test getting all realms."""
496496 pages .load ("blank.html" )
497497
498- realms = driver .script .get_realms ()
498+ realms = driver .script ._get_realms ()
499499
500500 assert len (realms ) > 0
501501 assert all (hasattr (realm , "realm" ) for realm in realms )
@@ -507,7 +507,7 @@ def test_get_realms_filtered_by_context(driver, pages):
507507 """Test getting realms filtered by context."""
508508 pages .load ("blank.html" )
509509
510- realms = driver .script .get_realms (context = driver .current_window_handle )
510+ realms = driver .script ._get_realms (context = driver .current_window_handle )
511511
512512 assert len (realms ) > 0
513513 # All realms should be associated with the specified context
@@ -520,7 +520,7 @@ def test_get_realms_filtered_by_type(driver, pages):
520520 """Test getting realms filtered by type."""
521521 pages .load ("blank.html" )
522522
523- realms = driver .script .get_realms (type = RealmType .WINDOW )
523+ realms = driver .script ._get_realms (type = RealmType .WINDOW )
524524
525525 assert len (realms ) > 0
526526 # All realms should be of the WINDOW type
@@ -533,15 +533,15 @@ def test_disown_handles(driver, pages):
533533 pages .load ("blank.html" )
534534
535535 # Create an object with root ownership (this will return a handle)
536- result = driver .script .evaluate (
536+ result = driver .script ._evaluate (
537537 "({foo: 'bar'})" , target = {"context" : driver .current_window_handle }, await_promise = False , result_ownership = "root"
538538 )
539539
540540 handle = result .result ["handle" ]
541541 assert handle is not None
542542
543543 # Use the handle in a function call (this should succeed)
544- result_before = driver .script .call_function (
544+ result_before = driver .script ._call_function (
545545 "function(obj) { return obj.foo; }" ,
546546 await_promise = False ,
547547 target = {"context" : driver .current_window_handle },
@@ -551,11 +551,11 @@ def test_disown_handles(driver, pages):
551551 assert result_before .result ["value" ] == "bar"
552552
553553 # Disown the handle
554- driver .script .disown (handles = [handle ], target = {"context" : driver .current_window_handle })
554+ driver .script ._disown (handles = [handle ], target = {"context" : driver .current_window_handle })
555555
556556 # Try using the disowned handle (this should fail)
557557 with pytest .raises (Exception ):
558- driver .script .call_function (
558+ driver .script ._call_function (
559559 "function(obj) { return obj.foo; }" ,
560560 await_promise = False ,
561561 target = {"context" : driver .current_window_handle },
0 commit comments