Skip to content

Commit f2e5095

Browse files
committed
lint
1 parent da7c3af commit f2e5095

File tree

6 files changed

+30
-36
lines changed

6 files changed

+30
-36
lines changed

examples/e2e/test_playwright.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ def playwright():
2626
yield p
2727

2828

29-
def test_playwright_basic(playwright: Playwright):
29+
def test_playwright_basic(playwright: Playwright) -> None:
3030
playwright_basic.run(playwright)
3131

3232

33-
def test_playwright_captcha(playwright: Playwright):
33+
def test_playwright_captcha(playwright: Playwright) -> None:
3434
if SKIP_CAPTCHA_SOLVING:
3535
pytest.skip("Skipping captcha solving")
3636
playwright_captcha.run(playwright)
3737

3838

39-
def test_playwright_contexts(playwright: Playwright):
39+
def test_playwright_contexts(playwright: Playwright) -> None:
4040
playwright_contexts.run(playwright)
4141

4242

43-
def test_playwright_downloads(playwright: Playwright):
43+
def test_playwright_downloads(playwright: Playwright) -> None:
4444
playwright_downloads.run(playwright)

examples/playwright_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99

1010

11-
def run(playwright: Playwright):
11+
def run(playwright: Playwright) -> None:
1212
# Create a session on Browserbase
1313
session = bb.sessions.create(project_id=BROWSERBASE_PROJECT_ID)
1414
assert session.id is not None

examples/playwright_captcha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
OVERRIDE_TIMEOUT = 60000 # 60 seconds, adjust as needed
1212

1313

14-
def run(playwright: Playwright):
14+
def run(playwright: Playwright) -> None:
1515
# Create a session on Browserbase
1616
session = bb.sessions.create(project_id=BROWSERBASE_PROJECT_ID)
1717
assert session.id is not None

examples/playwright_contexts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def find_cookie(browser: Browser, name: str) -> Optional[Cookie]:
2828
return next((cookie for cookie in cookies if cookie.get("name") == name), None)
2929

3030

31-
def run(playwright: Playwright):
31+
def run(playwright: Playwright) -> None:
3232
context_id = None
3333
session_id = None
3434
test_cookie_name = None

examples/playwright_downloads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_download(session_id: str) -> bytes:
1919
return response.read()
2020

2121

22-
def run(playwright: Playwright):
22+
def run(playwright: Playwright) -> None:
2323
# Create a session on Browserbase
2424
session = bb.sessions.create(project_id=BROWSERBASE_PROJECT_ID)
2525
assert session.id is not None

examples/playwright_extensions.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from io import BytesIO
55
from pathlib import Path
66

7-
from playwright.sync_api import Playwright, sync_playwright
7+
from playwright.sync_api import Page, Playwright, sync_playwright
88

99
from examples import (
1010
BROWSERBASE_API_KEY,
@@ -52,7 +52,7 @@ def zip_extension(path: Path = PATH_TO_EXTENSION, save_local: bool = False) -> B
5252
return memory_zip
5353

5454

55-
def create_extension():
55+
def create_extension() -> str:
5656
zip_data = zip_extension(save_local=True)
5757
extension: Extension = bb.extensions.create(
5858
file=("extension.zip", zip_data.getvalue())
@@ -64,11 +64,27 @@ def get_extension(id: str) -> Extension:
6464
return bb.extensions.retrieve(id)
6565

6666

67-
def delete_extension(id: str):
67+
def delete_extension(id: str) -> None:
6868
bb.extensions.delete(id)
6969

7070

71-
def run(playwright: Playwright):
71+
def check_for_message(page: Page, message: str) -> None:
72+
# Wait for the extension to load and log a message
73+
console_messages: list[str] = []
74+
page.on("console", lambda msg: console_messages.append(msg.text))
75+
page.goto("https://www.browserbase.com/")
76+
77+
start = time.time()
78+
while time.time() - start < 10:
79+
if message in console_messages:
80+
break
81+
assert (
82+
message in console_messages
83+
), f"Expected message not found in console logs. Messages: {console_messages}"
84+
85+
86+
def run(playwright: Playwright) -> None:
87+
expected_message = "browserbase test extension image loaded"
7288
extension_id = None
7389

7490
# Create extension
@@ -90,21 +106,7 @@ def run(playwright: Playwright):
90106
)
91107
context = browser.contexts[0]
92108
page = context.pages[0]
93-
94-
console_messages: list[str] = []
95-
page.on("console", lambda msg: console_messages.append(msg.text))
96-
97-
page.goto("https://www.browserbase.com/")
98-
99-
# Wait for the extension to load and log a message
100-
start = time.time()
101-
while time.time() - start < 10:
102-
if "browserbase test extension image loaded" in console_messages:
103-
break
104-
assert (
105-
"browserbase test extension image loaded" in console_messages
106-
), f"Expected message not found in console logs. Messages: {console_messages}"
107-
109+
check_for_message(page, expected_message)
108110
page.close()
109111
browser.close()
110112

@@ -126,15 +128,7 @@ def run(playwright: Playwright):
126128

127129
page.goto("https://www.browserbase.com/")
128130

129-
# Wait for the extension to load and log a message (longer timeout for proxies)
130-
start = time.time()
131-
while time.time() - start < 10:
132-
if "browserbase test extension image loaded" in console_messages:
133-
break
134-
assert (
135-
"browserbase test extension image loaded" in console_messages
136-
), f"Expected message not found in console logs. Messages: {console_messages}"
137-
131+
check_for_message(page, expected_message)
138132
page.close()
139133
browser.close()
140134

0 commit comments

Comments
 (0)