Skip to content

Commit 503d64e

Browse files
updates to integration tests
1 parent af9e033 commit 503d64e

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

stagehand/handlers/extract_handler.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,9 @@ async def extract(
159159
)
160160

161161
# Create ExtractResult object with extracted data as fields
162-
if isinstance(processed_data_payload, dict):
163-
result = ExtractResult(**processed_data_payload)
164-
elif hasattr(processed_data_payload, "model_dump"):
165-
# For Pydantic models, convert to dict and spread as fields
166-
result = ExtractResult(**processed_data_payload.model_dump())
167-
else:
168-
# For other data types, create with data field
169-
result = ExtractResult(data=processed_data_payload)
162+
# Instead of trying to spread dict fields, always use the data field approach
163+
# This ensures result.data is properly set for the page.extract() method
164+
result = ExtractResult(data=processed_data_payload)
170165

171166
return result
172167

tests/integration/test_observe_integration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ async def test_observe_form_elements_local(self, local_stagehand):
7979

8080
# Check observation structure
8181
for obs in observations:
82-
assert "selector" in obs
83-
assert obs["selector"] # Not empty
82+
assert hasattr(obs, "selector")
83+
assert obs.selector # Not empty
8484

8585
# Test finding specific labeled elements
8686
labeled_observations = await stagehand.page.observe("Find all form elements with labels")
@@ -108,8 +108,8 @@ async def test_observe_form_elements_browserbase(self, browserbase_stagehand):
108108

109109
# Check observation structure
110110
for obs in observations:
111-
assert "selector" in obs
112-
assert obs["selector"] # Not empty
111+
assert hasattr(obs, "selector")
112+
assert obs.selector # Not empty
113113

114114
@pytest.mark.asyncio
115115
@pytest.mark.local
@@ -195,7 +195,7 @@ async def test_observe_element_validation_local(self, local_stagehand):
195195

196196
# Validate that we can get element info for each observed element
197197
for element in form_elements[:3]: # Test first 3 to avoid timeout
198-
selector = element.get("selector")
198+
selector = element.selector
199199
if selector:
200200
try:
201201
# Try to check if element exists and is visible
@@ -277,7 +277,7 @@ async def test_observe_performance_local(self, local_stagehand):
277277
total_time = time.time() - start_time
278278

279279
# Multiple observations should still be reasonable
280-
assert total_time < 60.0 # 1 minute max for 3 operations
280+
assert total_time < 120.0 # 2 minutes max for 3 operations
281281

282282
@pytest.mark.asyncio
283283
@pytest.mark.e2e

tests/integration/test_stagehand_integration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ async def test_basic_navigation_and_observe_local(self, local_stagehand):
112112

113113
# Verify observation structure
114114
for obs in observations:
115-
assert "selector" in obs
116-
assert obs["selector"] # Not empty
115+
assert hasattr(obs, "selector")
116+
assert obs.selector # Not empty
117117

118118
@pytest.mark.asyncio
119119
@pytest.mark.browserbase
@@ -137,8 +137,8 @@ async def test_basic_navigation_and_observe_browserbase(self, browserbase_stageh
137137

138138
# Verify observation structure
139139
for obs in observations:
140-
assert "selector" in obs
141-
assert obs["selector"] # Not empty
140+
assert hasattr(obs, "selector")
141+
assert obs.selector # Not empty
142142

143143
@pytest.mark.asyncio
144144
@pytest.mark.local

0 commit comments

Comments
 (0)