@@ -14,12 +14,11 @@ def test_default_config_values(self):
1414 """Test that default config has expected values"""
1515 config = StagehandConfig ()
1616
17- assert config .env is None # Should be determined automatically
17+ assert config .env == "BROWSERBASE" # Default environment
1818 assert config .verbose == 1 # Default verbosity
19- assert config .dom_settle_timeout_ms == 30000 # Default timeout
19+ assert config .dom_settle_timeout_ms == 3000 # Default timeout
2020 assert config .self_heal is True # Default self-healing enabled
21- assert config .wait_for_captcha_solves is True # Default wait for captcha
22- assert config .headless is True # Default headless mode
21+ assert config .wait_for_captcha_solves is False # Default wait for captcha
2322 assert config .enable_caching is False # Default caching disabled
2423
2524 def test_config_with_custom_values (self ):
@@ -32,7 +31,6 @@ def test_config_with_custom_values(self):
3231 verbose = 2 ,
3332 dom_settle_timeout_ms = 5000 ,
3433 self_heal = False ,
35- headless = False ,
3634 system_prompt = "Custom system prompt"
3735 )
3836
@@ -43,7 +41,6 @@ def test_config_with_custom_values(self):
4341 assert config .verbose == 2
4442 assert config .dom_settle_timeout_ms == 5000
4543 assert config .self_heal is False
46- assert config .headless is False
4744 assert config .system_prompt == "Custom system prompt"
4845
4946 def test_browserbase_config (self ):
@@ -52,20 +49,13 @@ def test_browserbase_config(self):
5249 env = "BROWSERBASE" ,
5350 api_key = "bb-api-key" ,
5451 project_id = "bb-project-id" ,
55- browserbase_session_id = "existing-session" ,
56- browserbase_session_create_params = {
57- "browserSettings" : {
58- "viewport" : {"width" : 1920 , "height" : 1080 }
59- }
60- }
52+ browserbase_session_id = "existing-session"
6153 )
6254
6355 assert config .env == "BROWSERBASE"
6456 assert config .api_key == "bb-api-key"
6557 assert config .project_id == "bb-project-id"
6658 assert config .browserbase_session_id == "existing-session"
67- assert config .browserbase_session_create_params is not None
68- assert config .browserbase_session_create_params ["browserSettings" ]["viewport" ]["width" ] == 1920
6959
7060 def test_local_browser_config (self ):
7161 """Test configuration for local browser environment"""
@@ -77,33 +67,13 @@ def test_local_browser_config(self):
7767
7868 config = StagehandConfig (
7969 env = "LOCAL" ,
80- headless = False ,
8170 local_browser_launch_options = launch_options
8271 )
8372
8473 assert config .env == "LOCAL"
85- assert config .headless is False
8674 assert config .local_browser_launch_options == launch_options
8775 assert config .local_browser_launch_options ["executablePath" ] == "/opt/chrome/chrome"
8876
89- def test_model_client_options (self ):
90- """Test model client configuration options"""
91- model_options = {
92- "apiKey" : "test-api-key" ,
93- "temperature" : 0.7 ,
94- "max_tokens" : 2000 ,
95- "timeout" : 30
96- }
97-
98- config = StagehandConfig (
99- model_name = "gpt-4o" ,
100- model_client_options = model_options
101- )
102-
103- assert config .model_name == "gpt-4o"
104- assert config .model_client_options == model_options
105- assert config .model_client_options ["temperature" ] == 0.7
106-
10777 def test_config_with_overrides (self ):
10878 """Test the with_overrides method"""
10979 base_config = StagehandConfig (
@@ -151,22 +121,18 @@ def test_config_overrides_with_none_values(self):
151121 def test_config_with_nested_overrides (self ):
152122 """Test overrides with nested dictionary values"""
153123 base_config = StagehandConfig (
154- local_browser_launch_options = {"headless" : True },
155- model_client_options = {"temperature" : 0.5 }
124+ local_browser_launch_options = {"headless" : True }
156125 )
157126
158127 new_config = base_config .with_overrides (
159- local_browser_launch_options = {"headless" : False , "args" : ["--no-sandbox" ]},
160- model_client_options = {"temperature" : 0.8 , "max_tokens" : 1000 }
128+ local_browser_launch_options = {"headless" : False , "args" : ["--no-sandbox" ]}
161129 )
162130
163131 # Should completely replace nested dicts, not merge
164132 assert new_config .local_browser_launch_options == {"headless" : False , "args" : ["--no-sandbox" ]}
165- assert new_config .model_client_options == {"temperature" : 0.8 , "max_tokens" : 1000 }
166133
167134 # Original should be unchanged
168135 assert base_config .local_browser_launch_options == {"headless" : True }
169- assert base_config .model_client_options == {"temperature" : 0.5 }
170136
171137 def test_logger_configuration (self ):
172138 """Test logger configuration"""
@@ -182,14 +148,12 @@ def custom_logger(msg, level, category=None, auxiliary=None):
182148 assert config .verbose == 3
183149
184150 def test_timeout_configurations (self ):
185- """Test various timeout configurations"""
151+ """Test timeout configurations"""
186152 config = StagehandConfig (
187- dom_settle_timeout_ms = 15000 ,
188- act_timeout_ms = 45000
153+ dom_settle_timeout_ms = 15000
189154 )
190155
191156 assert config .dom_settle_timeout_ms == 15000
192- assert config .act_timeout_ms == 45000
193157
194158 def test_agent_configurations (self ):
195159 """Test agent-related configurations"""
@@ -210,7 +174,7 @@ def test_default_config_instance(self):
210174 assert isinstance (default_config , StagehandConfig )
211175 assert default_config .verbose == 1
212176 assert default_config .self_heal is True
213- assert default_config .headless is True
177+ assert default_config .env == "BROWSERBASE"
214178
215179 def test_default_config_immutability (self ):
216180 """Test that default_config modifications don't affect new instances"""
@@ -284,23 +248,19 @@ def test_invalid_verbose_level(self):
284248 def test_zero_timeout_values (self ):
285249 """Test with zero timeout values"""
286250 config = StagehandConfig (
287- dom_settle_timeout_ms = 0 ,
288- act_timeout_ms = 0
251+ dom_settle_timeout_ms = 0
289252 )
290253
291254 assert config .dom_settle_timeout_ms == 0
292- assert config .act_timeout_ms == 0
293255
294256 def test_negative_timeout_values (self ):
295257 """Test with negative timeout values"""
296258 config = StagehandConfig (
297- dom_settle_timeout_ms = - 1000 ,
298- act_timeout_ms = - 5000
259+ dom_settle_timeout_ms = - 1000
299260 )
300261
301262 # Should accept negative values (validation happens elsewhere)
302263 assert config .dom_settle_timeout_ms == - 1000
303- assert config .act_timeout_ms == - 5000
304264
305265
306266class TestConfigSerialization :
@@ -311,16 +271,14 @@ def test_config_dict_conversion(self):
311271 config = StagehandConfig (
312272 env = "LOCAL" ,
313273 api_key = "test-key" ,
314- verbose = 2 ,
315- headless = False
274+ verbose = 2
316275 )
317276
318277 # Should be able to convert to dict for inspection
319- config_dict = vars ( config )
278+ config_dict = config . model_dump ( )
320279 assert config_dict ["env" ] == "LOCAL"
321280 assert config_dict ["api_key" ] == "test-key"
322281 assert config_dict ["verbose" ] == 2
323- assert config_dict ["headless" ] is False
324282
325283 def test_config_string_representation (self ):
326284 """Test string representation of config"""
@@ -331,9 +289,9 @@ def test_config_string_representation(self):
331289 )
332290
333291 config_str = str (config )
334- assert "StagehandConfig" in config_str
335- # Should not expose sensitive information like API keys in string representation
336- # (This depends on how __str__ is implemented)
292+ # The pydantic model representation shows field values, not the class name
293+ assert "env='BROWSERBASE'" in config_str
294+ assert "api_key='test-key'" in config_str
337295
338296
339297class TestConfigEdgeCases :
@@ -345,7 +303,7 @@ def test_empty_config(self):
345303
346304 # Should create valid config with defaults
347305 assert config .verbose == 1 # Default value
348- assert config .env is None # No default
306+ assert config .env == "BROWSERBASE" # Default environment
349307 assert config .api_key is None
350308
351309 def test_config_with_empty_strings (self ):
@@ -375,28 +333,9 @@ def test_config_with_complex_options(self):
375333 }
376334 }
377335
378- config = StagehandConfig (
379- browserbase_session_create_params = complex_options
380- )
381-
382- assert config .browserbase_session_create_params == complex_options
383- assert config .browserbase_session_create_params ["browserSettings" ]["viewport" ]["width" ] == 1920
384- assert config .browserbase_session_create_params ["proxy" ]["server" ] == "proxy.example.com:8080"
385-
386- def test_config_with_callable_logger (self ):
387- """Test config with different types of logger functions"""
388- call_count = 0
389-
390- def counting_logger (msg , level , category = None , auxiliary = None ):
391- nonlocal call_count
392- call_count += 1
393-
394- config = StagehandConfig (logger = counting_logger )
395- assert config .logger == counting_logger
396-
397- # Test that logger is callable
398- assert callable (config .logger )
399-
400- # Test calling the logger
401- config .logger ("test message" , 1 )
402- assert call_count == 1
336+ # This will raise a validation error because browserbase_session_create_params
337+ # expects a specific schema, not arbitrary data
338+ with pytest .raises (Exception ): # Pydantic validation error
339+ config = StagehandConfig (
340+ browserbase_session_create_params = complex_options
341+ )
0 commit comments