Skip to content

Fix call signature for local screenshot #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stagehand/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ async def screenshot(self, options: Optional[dict] = None) -> str:

return result
else:
return await self._page.screenshot(options)
return await self._page.screenshot(**payload)

# Method to get or initialize the persistent CDP client
async def get_cdp_client(self) -> CDPSession:
Expand Down
58 changes: 40 additions & 18 deletions tests/integration/local/test_core_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,40 @@ async def test_stagehand_local_initialization(self, stagehand_local):
async def test_local_observe_and_act_workflow(self, stagehand_local):
"""Test core observe and act workflow in LOCAL mode - extracted from e2e tests."""
stagehand = stagehand_local

# Navigate to a form page for testing
await stagehand.page.goto("https://httpbin.org/forms/post")

# Test OBSERVE primitive: Find form elements
form_elements = await stagehand.page.observe("Find all form input elements")

# Verify observations
assert form_elements is not None
assert len(form_elements) > 0

# Verify observation structure
for obs in form_elements:
assert hasattr(obs, "selector")
assert obs.selector # Not empty

# Test ACT primitive: Fill form fields
await stagehand.page.act("Fill the customer name field with 'Local Integration Test'")
await stagehand.page.act(
"Fill the customer name field with 'Local Integration Test'"
)
await stagehand.page.act("Fill the telephone field with '555-LOCAL'")
await stagehand.page.act("Fill the email field with '[email protected]'")

# Verify actions worked by observing filled fields
filled_fields = await stagehand.page.observe("Find all filled form input fields")
filled_fields = await stagehand.page.observe(
"Find all filled form input fields"
)
assert filled_fields is not None
assert len(filled_fields) > 0

# Test interaction with specific elements
customer_field = await stagehand.page.observe("Find the customer name input field")
customer_field = await stagehand.page.observe(
"Find the customer name input field"
)
assert customer_field is not None
assert len(customer_field) > 0

Expand All @@ -82,17 +88,17 @@ async def test_local_observe_and_act_workflow(self, stagehand_local):
async def test_local_basic_navigation_and_observe(self, stagehand_local):
"""Test basic navigation and observe functionality in LOCAL mode"""
stagehand = stagehand_local

# Navigate to a simple page
await stagehand.page.goto("https://example.com")

# Observe elements on the page
observations = await stagehand.page.observe("Find all the links on the page")

# Verify we got some observations
assert observations is not None
assert len(observations) > 0

# Verify observation structure
for obs in observations:
assert hasattr(obs, "selector")
Expand All @@ -104,14 +110,30 @@ async def test_local_basic_navigation_and_observe(self, stagehand_local):
async def test_local_extraction_functionality(self, stagehand_local):
"""Test extraction functionality in LOCAL mode"""
stagehand = stagehand_local

# Navigate to a content-rich page
await stagehand.page.goto("https://news.ycombinator.com")

# Extract article titles using simple string instruction
articles_text = await stagehand.page.extract(
"Extract the titles of the first 3 articles on the page as a JSON list"
)

# Verify extraction worked
assert articles_text is not None
assert articles_text is not None

@pytest.mark.asyncio
@pytest.mark.integration
@pytest.mark.local
async def test_local_screenshot_functionality(self, stagehand_local):
"""Test screenshot functionality in LOCAL mode"""
stagehand = stagehand_local

# Navigate to a content-rich page
await stagehand.page.goto("https://news.ycombinator.com")

# Take a screenshot
screenshot = await stagehand.page.screenshot()

# Verify screenshot worked
assert screenshot is not None