From c9287f81a2311065b250cc3010ed35061001b470 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 17 Mar 2021 12:19:30 +0100 Subject: [PATCH 1/2] fix: enhance executable not found check --- playwright/_impl/_browser_type.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playwright/_impl/_browser_type.py b/playwright/_impl/_browser_type.py index db4cb1b53..2dce90ad7 100644 --- a/playwright/_impl/_browser_type.py +++ b/playwright/_impl/_browser_type.py @@ -69,7 +69,7 @@ async def launch( try: return from_channel(await self._channel.send("launch", params)) except Exception as e: - if f"{self.name}-" in str(e): + if "because executable doesn't exist" in str(e): raise not_installed_error(f'"{self.name}" browser was not found.') raise e @@ -124,7 +124,7 @@ async def launch_persistent_context( context._options = params return context except Exception as e: - if f"{self.name}-" in str(e): + if "because executable doesn't exist" in str(e): raise not_installed_error(f'"{self.name}" browser was not found.') raise e From 07d19cfffb29d187b45614f46d0415cd3e31563b Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 17 Mar 2021 16:03:45 +0100 Subject: [PATCH 2/2] added a test --- playwright/_impl/_helper.py | 2 +- tests/async/test_launcher.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/playwright/_impl/_helper.py b/playwright/_impl/_helper.py index 6b30a2bcd..e68fb36de 100644 --- a/playwright/_impl/_helper.py +++ b/playwright/_impl/_helper.py @@ -203,7 +203,7 @@ def is_safe_close_error(error: Exception) -> bool: def not_installed_error(message: str) -> Exception: - return Exception( + return Error( f""" ================================================================================ {message} diff --git a/tests/async/test_launcher.py b/tests/async/test_launcher.py index 008e43007..a87756177 100644 --- a/tests/async/test_launcher.py +++ b/tests/async/test_launcher.py @@ -121,3 +121,12 @@ async def test_browser_close_should_be_callable_twice(browser_type, launch_argum browser.close(), ) await browser.close() + + +async def test_browser_launch_non_existing_executable_path_shows_install_msg( + browser_type, + tmpdir, +): + with pytest.raises(Error) as exc_info: + await browser_type.launch(executable_path=tmpdir.join("executable")) + assert "python -m playwright install" in exc_info.value.message