@@ -14,12 +14,11 @@ def test_default_config_values(self):
14
14
"""Test that default config has expected values"""
15
15
config = StagehandConfig ()
16
16
17
- assert config .env is None # Should be determined automatically
17
+ assert config .env == "BROWSERBASE" # Default environment
18
18
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
20
20
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
23
22
assert config .enable_caching is False # Default caching disabled
24
23
25
24
def test_config_with_custom_values (self ):
@@ -32,7 +31,6 @@ def test_config_with_custom_values(self):
32
31
verbose = 2 ,
33
32
dom_settle_timeout_ms = 5000 ,
34
33
self_heal = False ,
35
- headless = False ,
36
34
system_prompt = "Custom system prompt"
37
35
)
38
36
@@ -43,7 +41,6 @@ def test_config_with_custom_values(self):
43
41
assert config .verbose == 2
44
42
assert config .dom_settle_timeout_ms == 5000
45
43
assert config .self_heal is False
46
- assert config .headless is False
47
44
assert config .system_prompt == "Custom system prompt"
48
45
49
46
def test_browserbase_config (self ):
@@ -52,20 +49,13 @@ def test_browserbase_config(self):
52
49
env = "BROWSERBASE" ,
53
50
api_key = "bb-api-key" ,
54
51
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"
61
53
)
62
54
63
55
assert config .env == "BROWSERBASE"
64
56
assert config .api_key == "bb-api-key"
65
57
assert config .project_id == "bb-project-id"
66
58
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
69
59
70
60
def test_local_browser_config (self ):
71
61
"""Test configuration for local browser environment"""
@@ -77,33 +67,13 @@ def test_local_browser_config(self):
77
67
78
68
config = StagehandConfig (
79
69
env = "LOCAL" ,
80
- headless = False ,
81
70
local_browser_launch_options = launch_options
82
71
)
83
72
84
73
assert config .env == "LOCAL"
85
- assert config .headless is False
86
74
assert config .local_browser_launch_options == launch_options
87
75
assert config .local_browser_launch_options ["executablePath" ] == "/opt/chrome/chrome"
88
76
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
-
107
77
def test_config_with_overrides (self ):
108
78
"""Test the with_overrides method"""
109
79
base_config = StagehandConfig (
@@ -151,22 +121,18 @@ def test_config_overrides_with_none_values(self):
151
121
def test_config_with_nested_overrides (self ):
152
122
"""Test overrides with nested dictionary values"""
153
123
base_config = StagehandConfig (
154
- local_browser_launch_options = {"headless" : True },
155
- model_client_options = {"temperature" : 0.5 }
124
+ local_browser_launch_options = {"headless" : True }
156
125
)
157
126
158
127
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" ]}
161
129
)
162
130
163
131
# Should completely replace nested dicts, not merge
164
132
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 }
166
133
167
134
# Original should be unchanged
168
135
assert base_config .local_browser_launch_options == {"headless" : True }
169
- assert base_config .model_client_options == {"temperature" : 0.5 }
170
136
171
137
def test_logger_configuration (self ):
172
138
"""Test logger configuration"""
@@ -182,14 +148,12 @@ def custom_logger(msg, level, category=None, auxiliary=None):
182
148
assert config .verbose == 3
183
149
184
150
def test_timeout_configurations (self ):
185
- """Test various timeout configurations"""
151
+ """Test timeout configurations"""
186
152
config = StagehandConfig (
187
- dom_settle_timeout_ms = 15000 ,
188
- act_timeout_ms = 45000
153
+ dom_settle_timeout_ms = 15000
189
154
)
190
155
191
156
assert config .dom_settle_timeout_ms == 15000
192
- assert config .act_timeout_ms == 45000
193
157
194
158
def test_agent_configurations (self ):
195
159
"""Test agent-related configurations"""
@@ -210,7 +174,7 @@ def test_default_config_instance(self):
210
174
assert isinstance (default_config , StagehandConfig )
211
175
assert default_config .verbose == 1
212
176
assert default_config .self_heal is True
213
- assert default_config .headless is True
177
+ assert default_config .env == "BROWSERBASE"
214
178
215
179
def test_default_config_immutability (self ):
216
180
"""Test that default_config modifications don't affect new instances"""
@@ -284,23 +248,19 @@ def test_invalid_verbose_level(self):
284
248
def test_zero_timeout_values (self ):
285
249
"""Test with zero timeout values"""
286
250
config = StagehandConfig (
287
- dom_settle_timeout_ms = 0 ,
288
- act_timeout_ms = 0
251
+ dom_settle_timeout_ms = 0
289
252
)
290
253
291
254
assert config .dom_settle_timeout_ms == 0
292
- assert config .act_timeout_ms == 0
293
255
294
256
def test_negative_timeout_values (self ):
295
257
"""Test with negative timeout values"""
296
258
config = StagehandConfig (
297
- dom_settle_timeout_ms = - 1000 ,
298
- act_timeout_ms = - 5000
259
+ dom_settle_timeout_ms = - 1000
299
260
)
300
261
301
262
# Should accept negative values (validation happens elsewhere)
302
263
assert config .dom_settle_timeout_ms == - 1000
303
- assert config .act_timeout_ms == - 5000
304
264
305
265
306
266
class TestConfigSerialization :
@@ -311,16 +271,14 @@ def test_config_dict_conversion(self):
311
271
config = StagehandConfig (
312
272
env = "LOCAL" ,
313
273
api_key = "test-key" ,
314
- verbose = 2 ,
315
- headless = False
274
+ verbose = 2
316
275
)
317
276
318
277
# Should be able to convert to dict for inspection
319
- config_dict = vars ( config )
278
+ config_dict = config . model_dump ( )
320
279
assert config_dict ["env" ] == "LOCAL"
321
280
assert config_dict ["api_key" ] == "test-key"
322
281
assert config_dict ["verbose" ] == 2
323
- assert config_dict ["headless" ] is False
324
282
325
283
def test_config_string_representation (self ):
326
284
"""Test string representation of config"""
@@ -331,9 +289,9 @@ def test_config_string_representation(self):
331
289
)
332
290
333
291
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
337
295
338
296
339
297
class TestConfigEdgeCases :
@@ -345,7 +303,7 @@ def test_empty_config(self):
345
303
346
304
# Should create valid config with defaults
347
305
assert config .verbose == 1 # Default value
348
- assert config .env is None # No default
306
+ assert config .env == "BROWSERBASE" # Default environment
349
307
assert config .api_key is None
350
308
351
309
def test_config_with_empty_strings (self ):
@@ -375,28 +333,9 @@ def test_config_with_complex_options(self):
375
333
}
376
334
}
377
335
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