@@ -256,30 +256,6 @@ async def test_act_with_options_browserbase(self, mock_stagehand_page):
256
256
}
257
257
)
258
258
assert isinstance (result , ActResult )
259
-
260
- @pytest .mark .asyncio
261
- async def test_act_ignores_kwargs_with_observe_result (self , mock_stagehand_page ):
262
- """Test that kwargs are ignored when using ObserveResult"""
263
- mock_stagehand_page ._stagehand .env = "LOCAL"
264
-
265
- observe_result = ObserveResult (
266
- selector = "#test" ,
267
- description = "test" ,
268
- method = "click"
269
- )
270
-
271
- mock_act_handler = MagicMock ()
272
- mock_act_handler .act = AsyncMock (return_value = ActResult (
273
- success = True ,
274
- message = "Done" ,
275
- action = "click"
276
- ))
277
- mock_stagehand_page ._act_handler = mock_act_handler
278
-
279
- # Should warn about ignored kwargs
280
- await mock_stagehand_page .act (observe_result , model_name = "ignored" )
281
-
282
- mock_stagehand_page ._stagehand .logger .warning .assert_called ()
283
259
284
260
285
261
class TestObserveFunctionality :
@@ -311,26 +287,6 @@ async def test_observe_with_string_instruction_local(self, mock_stagehand_page):
311
287
assert result [0 ].selector == "#submit-btn"
312
288
mock_observe_handler .observe .assert_called_once ()
313
289
314
- @pytest .mark .asyncio
315
- async def test_observe_with_options_object (self , mock_stagehand_page ):
316
- """Test observe() with ObserveOptions object"""
317
- mock_stagehand_page ._stagehand .env = "LOCAL"
318
-
319
- options = ObserveOptions (
320
- instruction = "find buttons" ,
321
- only_visible = True ,
322
- return_action = True
323
- )
324
-
325
- mock_observe_handler = MagicMock ()
326
- mock_observe_handler .observe = AsyncMock (return_value = [])
327
- mock_stagehand_page ._observe_handler = mock_observe_handler
328
-
329
- result = await mock_stagehand_page .observe (options )
330
-
331
- assert isinstance (result , list )
332
- mock_observe_handler .observe .assert_called_with (options , from_act = False )
333
-
334
290
@pytest .mark .asyncio
335
291
async def test_observe_browserbase_mode (self , mock_stagehand_page ):
336
292
"""Test observe() in BROWSERBASE mode"""
@@ -352,23 +308,6 @@ async def test_observe_browserbase_mode(self, mock_stagehand_page):
352
308
assert len (result ) == 1
353
309
assert isinstance (result [0 ], ObserveResult )
354
310
assert result [0 ].selector == "#test-btn"
355
-
356
- @pytest .mark .asyncio
357
- async def test_observe_with_none_options (self , mock_stagehand_page ):
358
- """Test observe() with None options"""
359
- mock_stagehand_page ._stagehand .env = "LOCAL"
360
-
361
- mock_observe_handler = MagicMock ()
362
- mock_observe_handler .observe = AsyncMock (return_value = [])
363
- mock_stagehand_page ._observe_handler = mock_observe_handler
364
-
365
- # This test should pass a default instruction instead of None
366
- result = await mock_stagehand_page .observe ("default instruction" )
367
-
368
- assert isinstance (result , list )
369
- # Should create ObserveOptions with the instruction
370
- call_args = mock_observe_handler .observe .call_args [0 ][0 ]
371
- assert isinstance (call_args , ObserveOptions )
372
311
373
312
374
313
class TestExtractFunctionality :
@@ -421,34 +360,7 @@ class ProductSchema(BaseModel):
421
360
assert isinstance (call_args [0 ][0 ], ExtractOptions ) # First argument should be ExtractOptions
422
361
assert call_args [0 ][1 ] == ProductSchema # Second argument should be the Pydantic model
423
362
424
- @pytest .mark .asyncio
425
- async def test_extract_with_dict_schema (self , mock_stagehand_page ):
426
- """Test extract() with dictionary schema"""
427
- mock_stagehand_page ._stagehand .env = "LOCAL"
428
-
429
- schema = {
430
- "type" : "object" ,
431
- "properties" : {
432
- "title" : {"type" : "string" },
433
- "content" : {"type" : "string" }
434
- }
435
- }
436
-
437
- options = ExtractOptions (
438
- instruction = "extract content" ,
439
- schema_definition = schema
440
- )
441
-
442
- mock_extract_handler = MagicMock ()
443
- mock_extract_result = MagicMock ()
444
- mock_extract_result .data = {"title" : "Test" , "content" : "Test content" }
445
- mock_extract_handler .extract = AsyncMock (return_value = mock_extract_result )
446
- mock_stagehand_page ._extract_handler = mock_extract_handler
447
-
448
- result = await mock_stagehand_page .extract (options )
449
-
450
- assert result == {"title" : "Test" , "content" : "Test content" }
451
-
363
+
452
364
@pytest .mark .asyncio
453
365
async def test_extract_with_none_options (self , mock_stagehand_page ):
454
366
"""Test extract() with None options (extract entire page)"""
@@ -490,16 +402,6 @@ async def test_extract_browserbase_mode(self, mock_stagehand_page):
490
402
class TestScreenshotFunctionality :
491
403
"""Test screenshot functionality"""
492
404
493
- @pytest .mark .asyncio
494
- async def test_screenshot_local_mode_not_implemented (self , mock_stagehand_page ):
495
- """Test that screenshot in LOCAL mode shows warning"""
496
- mock_stagehand_page ._stagehand .env = "LOCAL"
497
-
498
- result = await mock_stagehand_page .screenshot ()
499
-
500
- assert result is None
501
- mock_stagehand_page ._stagehand .logger .warning .assert_called ()
502
-
503
405
@pytest .mark .asyncio
504
406
async def test_screenshot_browserbase_mode (self , mock_stagehand_page ):
505
407
"""Test screenshot in BROWSERBASE mode"""
@@ -636,58 +538,3 @@ async def test_wait_for_settled_dom_error_handling(self, mock_stagehand_page):
636
538
# If we get here, it means the method handled the exception gracefully
637
539
except Exception :
638
540
pytest .fail ("_wait_for_settled_dom should handle exceptions gracefully" )
639
-
640
-
641
- class TestPageIntegration :
642
- """Test page integration workflows"""
643
-
644
- @pytest .mark .asyncio
645
- async def test_observe_then_act_workflow (self , mock_stagehand_page ):
646
- """Test workflow of observing then acting on results"""
647
- mock_stagehand_page ._stagehand .env = "LOCAL"
648
-
649
- # Mock observe handler
650
- mock_observe_handler = MagicMock ()
651
- observe_result = ObserveResult (
652
- selector = "#button" ,
653
- description = "Test button" ,
654
- method = "click" ,
655
- arguments = []
656
- )
657
- mock_observe_handler .observe = AsyncMock (return_value = [observe_result ])
658
- mock_stagehand_page ._observe_handler = mock_observe_handler
659
-
660
- # Mock act handler
661
- mock_act_handler = MagicMock ()
662
- mock_act_handler .act = AsyncMock (return_value = ActResult (
663
- success = True ,
664
- message = "Button clicked" ,
665
- action = "click"
666
- ))
667
- mock_stagehand_page ._act_handler = mock_act_handler
668
-
669
- # Test workflow
670
- observe_results = await mock_stagehand_page .observe ("find a button" )
671
- assert len (observe_results ) == 1
672
-
673
- act_result = await mock_stagehand_page .act (observe_results [0 ])
674
- assert act_result .success is True
675
-
676
- @pytest .mark .asyncio
677
- async def test_navigation_then_extraction_workflow (self , mock_stagehand_page , sample_html_content ):
678
- """Test workflow of navigation then data extraction"""
679
- mock_stagehand_page ._stagehand .env = "LOCAL"
680
-
681
- # Mock extract handler
682
- mock_extract_handler = MagicMock ()
683
- mock_extract_result = MagicMock ()
684
- mock_extract_result .data = {"title" : "Sample Post Title" }
685
- mock_extract_handler .extract = AsyncMock (return_value = mock_extract_result )
686
- mock_stagehand_page ._extract_handler = mock_extract_handler
687
-
688
- # Test navigation
689
- await mock_stagehand_page .goto ("https://example.com" )
690
-
691
- # Test extraction
692
- result = await mock_stagehand_page .extract ("extract the title" )
693
- assert result == {"title" : "Sample Post Title" }
0 commit comments