11from playwright .sync_api import Playwright , sync_playwright
22
3- from examples import (BROWSERBASE_API_KEY , BROWSERBASE_CONNECT_URL ,
4- BROWSERBASE_PROJECT_ID , bb )
3+ from examples import (
4+ BROWSERBASE_API_KEY ,
5+ BROWSERBASE_CONNECT_URL ,
6+ BROWSERBASE_PROJECT_ID ,
7+ bb ,
8+ )
59
610
711def run (playwright : Playwright ):
812 # Create a session on Browserbase
913 session = bb .sessions .create (project_id = BROWSERBASE_PROJECT_ID )
14+ assert session .id is not None
15+ assert session .status == "RUNNING" , f"Session status is { session .status } "
1016
1117 # Connect to the remote session
1218 connect_url = (
@@ -19,14 +25,18 @@ def run(playwright: Playwright):
1925
2026 # Execute Playwright actions on the remote browser tab
2127 page .goto ("https://news.ycombinator.com/" )
22- assert page .title == "Hacker News"
28+ page_title = page .title ()
29+ assert (
30+ page_title == "Hacker News"
31+ ), f"Page title is not 'Hacker News', it is '{ page_title } '"
2332 page .screenshot (path = "screenshot.png" )
2433
2534 updated_session = bb .sessions .retrieve (session .id )
26- print (updated_session .)
35+ print (updated_session .status )
2736
2837 page .close ()
2938 browser .close ()
39+ return session .id
3040
3141
3242if __name__ == "__main__" :
0 commit comments