-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add test (requires manual test with pyvenv) for #10
- fix #10
- Loading branch information
1 parent
602b680
commit 4e9c7af
Showing
5 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
import subprocess | ||
from cdp_patches.input import SyncInput, AsyncInput | ||
|
||
|
||
def test_raises_from_pid(): | ||
with pytest.raises(TimeoutError): | ||
sync_input = SyncInput(pid=-1, window_timeout=1) | ||
sync_input.click("left", 100, 100) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_raises_from_pid(): | ||
with pytest.raises(TimeoutError): | ||
sync_input = await AsyncInput(pid=-1, window_timeout=1) | ||
await sync_input.click("left", 100, 100) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_from_pid(chrome_proc: subprocess.Popen): | ||
sync_input = await AsyncInput(pid=chrome_proc.pid, window_timeout=1) | ||
await sync_input.click("left", 100, 100) | ||
|
||
|
||
def test_sync_from_pid(chrome_proc: subprocess.Popen): | ||
sync_input = SyncInput(pid=chrome_proc.pid, window_timeout=1) | ||
sync_input.click("left", 100, 100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import sys | ||
import socket | ||
from contextlib import closing | ||
|
||
IS_POSIX = sys.platform.startswith(("darwin", "cygwin", "linux", "linux2")) | ||
|
||
|
||
def find_chrome_executable() -> str: | ||
""" | ||
Finds the Chrome, Chrome beta, Chrome canary, Chromium executable | ||
Returns | ||
------- | ||
executable_path : str | ||
the full file path to found executable | ||
""" | ||
candidates = set() | ||
if IS_POSIX: | ||
for item in os.environ.get("PATH", "").split(os.pathsep): | ||
for subitem in ( | ||
"google-chrome", | ||
"chromium", | ||
"chromium-browser", | ||
"chrome", | ||
"google-chrome-stable", | ||
): | ||
candidates.add(os.sep.join((item, subitem))) | ||
if "darwin" in sys.platform: | ||
candidates.update( | ||
[ | ||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", | ||
"/Applications/Chromium.app/Contents/MacOS/Chromium", | ||
] | ||
) | ||
else: | ||
for item in map( | ||
os.environ.get, | ||
("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA", "PROGRAMW6432"), | ||
): | ||
if item is not None: | ||
for subitem in ( | ||
"Google/Chrome/Application", | ||
"Google/Chrome Beta/Application", | ||
"Google/Chrome Canary/Application", | ||
): | ||
candidates.add(os.sep.join((item, subitem, "chrome.exe"))) | ||
for candidate in candidates: | ||
if os.path.exists(candidate) and os.access(candidate, os.X_OK): | ||
return os.path.normpath(candidate) | ||
raise FileNotFoundError("Couldn't find installed Chrome or Chromium executable") | ||
|
||
|
||
def random_port(host: str = None) -> int: | ||
if not host: | ||
host = '' | ||
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: | ||
s.bind((host, 0)) | ||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
return s.getsockname()[1] |