@@ -95,35 +95,9 @@ async def test_wichita_local(self, local_stagehand):
9595 )
9696
9797 result = await stagehand .page .extract (extract_options )
98- #TODO - how to unify the extract result handling between LOCAL and BROWSERBASE?
99-
100- # Handle result based on the mode with better error handling
101- total_results = None
102-
103- if hasattr (result , 'data' ) and result .data :
104- # BROWSERBASE mode format
105- try :
106- bid_data = BidResults .model_validate (result .data )
107- total_results = bid_data .total_results
108- except Exception as e :
109- # If validation fails, try to extract from raw data
110- print (f"Schema validation failed: { e } " )
111- print (f"Raw result.data: { result .data } " )
112- if isinstance (result .data , dict ):
113- # Try different field names
114- total_results = (
115- result .data .get ('total_results' ) or
116- result .data .get ('totalResults' ) or
117- str (result .data )
118- )
119- else :
120- total_results = str (result .data )
121- elif hasattr (result , 'total_results' ):
122- # LOCAL mode format - result is the Pydantic model instance
123- total_results = result .total_results
124- else :
125- # Fallback - try to get total_results from the result directly
126- total_results = getattr (result , 'total_results' , str (result ))
98+
99+ # Both LOCAL and BROWSERBASE modes return the Pydantic model instance directly
100+ total_results = result .total_results
127101
128102 # Ensure we got some result
129103 assert total_results is not None , f"Failed to extract total_results from the page. Result: { result } "
@@ -177,35 +151,8 @@ async def test_wichita_browserbase(self, browserbase_stagehand):
177151
178152 result = await stagehand .page .extract (extract_options )
179153
180- #TODO - how to unify the extract result handling between LOCAL and BROWSERBASE?
181-
182- # Handle result based on the mode with better error handling
183- total_results = None
184-
185- if hasattr (result , 'data' ) and result .data :
186- # BROWSERBASE mode format
187- try :
188- bid_data = BidResults .model_validate (result .data )
189- total_results = bid_data .total_results
190- except Exception as e :
191- # If validation fails, try to extract from raw data
192- print (f"Schema validation failed: { e } " )
193- print (f"Raw result.data: { result .data } " )
194- if isinstance (result .data , dict ):
195- # Try different field names
196- total_results = (
197- result .data .get ('total_results' ) or
198- result .data .get ('totalResults' ) or
199- str (result .data )
200- )
201- else :
202- total_results = str (result .data )
203- elif hasattr (result , 'total_results' ):
204- # LOCAL mode format - result is the Pydantic model instance
205- total_results = result .total_results
206- else :
207- # Fallback - try to get total_results from the result directly
208- total_results = getattr (result , 'total_results' , str (result ))
154+ # Both LOCAL and BROWSERBASE modes return the Pydantic model instance directly
155+ total_results = result .total_results
209156
210157 # Ensure we got some result
211158 assert total_results is not None , f"Failed to extract total_results from the page. Result: { result } "
0 commit comments