Skip to content

Commit a0cebee

Browse files
updates
1 parent 0e21f24 commit a0cebee

File tree

8 files changed

+92
-6
lines changed

8 files changed

+92
-6
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ jobs:
115115
name: API Integration Tests
116116
runs-on: ubuntu-latest
117117
needs: test-unit
118-
if: |
119-
github.event_name == 'schedule' ||
120-
contains(github.event.pull_request.labels.*.name, 'test-api') ||
121-
contains(github.event.pull_request.labels.*.name, 'api')
122118

123119
steps:
124120
- uses: actions/checkout@v4
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/integration/api/test_core_api.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import pytest
44
import pytest_asyncio
5+
from pydantic import BaseModel, Field
56

67
from stagehand import Stagehand, StagehandConfig
8+
from stagehand.schemas import ExtractOptions
79

810

911
skip_if_no_creds = pytest.mark.skipif(
@@ -12,6 +14,12 @@
1214
)
1315

1416

17+
class Article(BaseModel):
18+
"""Schema for article extraction tests"""
19+
title: str = Field(..., description="The title of the article")
20+
summary: str = Field(None, description="A brief summary or description of the article")
21+
22+
1523
@pytest_asyncio.fixture(scope="module")
1624
@skip_if_no_creds
1725
async def stagehand_api():
@@ -35,4 +43,48 @@ async def stagehand_api():
3543
@pytest.mark.asyncio
3644
async def test_stagehand_api_initialization(stagehand_api):
3745
"""Ensure that Stagehand initializes correctly against the Browserbase API."""
38-
assert stagehand_api.session_id is not None
46+
assert stagehand_api.session_id is not None
47+
48+
49+
@skip_if_no_creds
50+
@pytest.mark.integration
51+
@pytest.mark.api
52+
@pytest.mark.asyncio
53+
async def test_api_extract_functionality(stagehand_api):
54+
"""Test core extract functionality in API mode - extracted from e2e tests."""
55+
stagehand = stagehand_api
56+
57+
# Navigate to a content-rich page
58+
await stagehand.page.goto("https://news.ycombinator.com")
59+
60+
# Test simple text-based extraction
61+
titles_text = await stagehand.page.extract(
62+
"Extract the titles of the first 3 articles on the page as a JSON array"
63+
)
64+
65+
# Verify extraction worked
66+
assert titles_text is not None
67+
68+
# Test schema-based extraction
69+
extract_options = ExtractOptions(
70+
instruction="Extract the first article's title and any available summary",
71+
schema_definition=Article
72+
)
73+
74+
article_data = await stagehand.page.extract(extract_options)
75+
assert article_data is not None
76+
77+
# Validate the extracted data structure (Browserbase format)
78+
if hasattr(article_data, 'data') and article_data.data:
79+
# BROWSERBASE mode format
80+
article = Article.model_validate(article_data.data)
81+
assert article.title
82+
assert len(article.title) > 0
83+
elif hasattr(article_data, 'title'):
84+
# Fallback format
85+
article = Article.model_validate(article_data.model_dump())
86+
assert article.title
87+
assert len(article.title) > 0
88+
89+
# Verify API session is active
90+
assert stagehand.session_id is not None

tests/integration/local/test_core_local.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,42 @@ async def stagehand_local():
1919
@pytest.mark.asyncio
2020
async def test_stagehand_local_initialization(stagehand_local):
2121
"""Ensure that Stagehand initializes correctly in LOCAL mode."""
22-
assert stagehand_local._initialized is True
22+
assert stagehand_local._initialized is True
23+
24+
25+
@pytest.mark.integration
26+
@pytest.mark.local
27+
@pytest.mark.asyncio
28+
async def test_local_observe_and_act_workflow(stagehand_local):
29+
"""Test core observe and act workflow in LOCAL mode - extracted from e2e tests."""
30+
stagehand = stagehand_local
31+
32+
# Navigate to a form page for testing
33+
await stagehand.page.goto("https://httpbin.org/forms/post")
34+
35+
# Test OBSERVE primitive: Find form elements
36+
form_elements = await stagehand.page.observe("Find all form input elements")
37+
38+
# Verify observations
39+
assert form_elements is not None
40+
assert len(form_elements) > 0
41+
42+
# Verify observation structure
43+
for obs in form_elements:
44+
assert hasattr(obs, "selector")
45+
assert obs.selector # Not empty
46+
47+
# Test ACT primitive: Fill form fields
48+
await stagehand.page.act("Fill the customer name field with 'Local Integration Test'")
49+
await stagehand.page.act("Fill the telephone field with '555-LOCAL'")
50+
await stagehand.page.act("Fill the email field with '[email protected]'")
51+
52+
# Verify actions worked by observing filled fields
53+
filled_fields = await stagehand.page.observe("Find all filled form input fields")
54+
assert filled_fields is not None
55+
assert len(filled_fields) > 0
56+
57+
# Test interaction with specific elements
58+
customer_field = await stagehand.page.observe("Find the customer name input field")
59+
assert customer_field is not None
60+
assert len(customer_field) > 0

0 commit comments

Comments
 (0)