Skip to content

Commit

Permalink
Rename tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elacuesta committed Jul 7, 2024
1 parent 6e502b7 commit e31bee0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ async def _run_chromium_devtools() -> Tuple[subprocess.Popen, str]:
return proc, devtools_url


def _run_playwright_browser_server() -> Tuple[subprocess.Popen, str]:
def _run_chromium_browser_server() -> Tuple[subprocess.Popen, str]:
"""Start a Playwright server in a separate process, return the process
object and a string with its websocket endpoint.
Pass fixed port and ws path as arguments instead of allowing Playwright
to choose, for some reason I was unable to capture stdout/stderr :shrug:
"""
port = str(random.randint(60_000, 63_000))
ws_path = str(uuid.uuid4())
launch_server_script_path = str(Path(__file__).parent.parent / "launch_browser_server.js")
launch_server_script_path = str(Path(__file__).parent.parent / "launch_chromium_server.js")
command = ["node", launch_server_script_path, port, ws_path]
proc = subprocess.Popen(command) # pylint: disable=consider-using-with
return proc, f"ws://localhost:{port}/{ws_path}"


@asynccontextmanager
async def remote_browser(is_chrome_devtools_protocol: bool = True):
async def remote_chromium(with_devtools_protocol: bool = True):
"""Launch a remote browser that lasts while in the context."""
proc = url = None
try:
if is_chrome_devtools_protocol:
if with_devtools_protocol:
proc, url = await _run_chromium_devtools()
else:
proc, url = _run_playwright_browser_server()
proc, url = _run_chromium_browser_server()
await asyncio.sleep(1) # allow some time for the browser to start
except Exception:
pass
Expand All @@ -77,15 +77,15 @@ async def remote_browser(is_chrome_devtools_protocol: bool = True):
proc.communicate()


class TestRemote(IsolatedAsyncioTestCase):
class TestRemoteBrowser(IsolatedAsyncioTestCase):
@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog):
caplog.set_level(logging.DEBUG)
self._caplog = caplog

@allow_windows
async def test_connect_devtools(self):
async with remote_browser(is_chrome_devtools_protocol=True) as devtools_url:
async with remote_chromium(with_devtools_protocol=True) as devtools_url:
settings_dict = {
"PLAYWRIGHT_CDP_URL": devtools_url,
"PLAYWRIGHT_LAUNCH_OPTIONS": {"headless": True},
Expand All @@ -103,7 +103,7 @@ async def test_connect_devtools(self):

@allow_windows
async def test_connect(self):
async with remote_browser(is_chrome_devtools_protocol=False) as browser_url:
async with remote_chromium(with_devtools_protocol=False) as browser_url:
settings_dict = {
"PLAYWRIGHT_CONNECT_URL": browser_url,
"PLAYWRIGHT_LAUNCH_OPTIONS": {"headless": True},
Expand Down

0 comments on commit e31bee0

Please sign in to comment.