Skip to content

Commit 694c4fb

Browse files
second regression test
1 parent 297d154 commit 694c4fb

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
"""
2+
Regression test for instructions functionality.
3+
4+
This test verifies that special instruction actions work correctly,
5+
based on the TypeScript instructions evaluation.
6+
"""
7+
8+
import os
9+
import pytest
10+
import pytest_asyncio
11+
12+
from stagehand import Stagehand, StagehandConfig
13+
14+
15+
class TestInstructions:
16+
"""Regression test for instructions functionality"""
17+
18+
@pytest.fixture(scope="class")
19+
def local_config(self):
20+
"""Configuration for LOCAL mode testing"""
21+
return StagehandConfig(
22+
env="LOCAL",
23+
model_name="gpt-4o-mini",
24+
headless=True,
25+
verbose=1,
26+
dom_settle_timeout_ms=2000,
27+
model_client_options={"apiKey": os.getenv("MODEL_API_KEY") or os.getenv("OPENAI_API_KEY")},
28+
)
29+
30+
@pytest.fixture(scope="class")
31+
def browserbase_config(self):
32+
"""Configuration for BROWSERBASE mode testing"""
33+
return StagehandConfig(
34+
env="BROWSERBASE",
35+
api_key=os.getenv("BROWSERBASE_API_KEY"),
36+
project_id=os.getenv("BROWSERBASE_PROJECT_ID"),
37+
model_name="gpt-4o",
38+
headless=False,
39+
verbose=2,
40+
model_client_options={"apiKey": os.getenv("MODEL_API_KEY") or os.getenv("OPENAI_API_KEY")},
41+
)
42+
43+
@pytest_asyncio.fixture
44+
async def local_stagehand(self, local_config):
45+
"""Create a Stagehand instance for LOCAL testing"""
46+
stagehand = Stagehand(config=local_config)
47+
await stagehand.init()
48+
yield stagehand
49+
await stagehand.close()
50+
51+
@pytest_asyncio.fixture
52+
async def browserbase_stagehand(self, browserbase_config):
53+
"""Create a Stagehand instance for BROWSERBASE testing"""
54+
if not (os.getenv("BROWSERBASE_API_KEY") and os.getenv("BROWSERBASE_PROJECT_ID")):
55+
pytest.skip("Browserbase credentials not available")
56+
57+
stagehand = Stagehand(config=browserbase_config)
58+
await stagehand.init()
59+
yield stagehand
60+
await stagehand.close()
61+
62+
@pytest.mark.asyncio
63+
@pytest.mark.regression
64+
@pytest.mark.local
65+
async def test_instructions_local(self, local_stagehand):
66+
"""
67+
Regression test: instructions
68+
69+
Mirrors the TypeScript instructions evaluation:
70+
- Navigate to docs.browserbase.com
71+
- Perform special action with "secret12345"
72+
- Verify correct navigation to introduction page
73+
"""
74+
stagehand = local_stagehand
75+
76+
await stagehand.page.goto("https://docs.browserbase.com/")
77+
78+
result = await stagehand.page.act("secret12345")
79+
80+
# Wait for page to settle after the action
81+
await stagehand.page.wait_for_load_state("domcontentloaded")
82+
83+
current_url = stagehand.page.url
84+
expected_url = "https://docs.browserbase.com/introduction/what-is-browserbase"
85+
86+
# Test passes if we navigated to the correct URL
87+
assert current_url == expected_url, f"Expected URL {expected_url}, but got {current_url}"
88+
89+
@pytest.mark.asyncio
90+
@pytest.mark.regression
91+
@pytest.mark.api
92+
@pytest.mark.skipif(
93+
not (os.getenv("BROWSERBASE_API_KEY") and os.getenv("BROWSERBASE_PROJECT_ID")),
94+
reason="Browserbase credentials not available"
95+
)
96+
async def test_instructions_browserbase(self, browserbase_stagehand):
97+
"""
98+
Regression test: instructions (Browserbase)
99+
100+
Same test as local but running in Browserbase environment.
101+
"""
102+
stagehand = browserbase_stagehand
103+
104+
await stagehand.page.goto("https://docs.browserbase.com/")
105+
106+
result = await stagehand.page.act("secret12345")
107+
108+
# Wait for page to settle after the action
109+
await stagehand.page.wait_for_load_state("domcontentloaded")
110+
111+
current_url = stagehand.page.url
112+
expected_url = "https://docs.browserbase.com/introduction/what-is-browserbase"
113+
114+
# Test passes if we navigated to the correct URL
115+
assert current_url == expected_url, f"Expected URL {expected_url}, but got {current_url}"

0 commit comments

Comments
 (0)