File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 25
25
26
26
from playwright .async_api import Playwright as AsyncPlaywright
27
27
from playwright .connection import Connection
28
- from playwright .helper import not_installed_error
28
+ from playwright .helper import Error , not_installed_error
29
29
from playwright .object_factory import create_remote_object
30
30
from playwright .playwright import Playwright
31
31
from playwright .sync_api import Playwright as SyncPlaywright
@@ -72,7 +72,10 @@ async def run_driver_async() -> Connection:
72
72
73
73
74
74
def run_driver () -> Connection :
75
- return asyncio .get_event_loop ().run_until_complete (run_driver_async ())
75
+ loop = asyncio .get_event_loop ()
76
+ if loop .is_running ():
77
+ raise Error ("Can only run one Playwright at a time." )
78
+ return loop .run_until_complete (run_driver_async ())
76
79
77
80
78
81
class SyncPlaywrightContextManager :
Original file line number Diff line number Diff line change @@ -205,3 +205,12 @@ def test_sync_workers_page_workers(page: Page, server):
205
205
206
206
page .goto (server .EMPTY_PAGE )
207
207
assert len (page .workers ) == 0
208
+
209
+
210
+ def test_sync_playwright_multiple_times ():
211
+ with sync_playwright () as pw1 :
212
+ assert pw1 .chromium
213
+ with pytest .raises (Error ) as exc :
214
+ with sync_playwright () as pw2 :
215
+ assert pw1 .chromium == pw2 .chromium
216
+ assert "Can only run one Playwright at a time." in exc .value .message
You can’t perform that action at this time.
0 commit comments