diff --git a/.gitignore b/.gitignore index e152e6ea..781d9ca4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ __pycache__ dist build +Drivers Eel.egg-info .tmp .DS_Store diff --git a/requirements-test.txt b/requirements-test.txt index a773aeb6..0a9d9728 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -4,3 +4,4 @@ psutil==5.9.2 pytest==7.0.1 pytest-timeout==2.1.0 selenium==3.141.0 +webdriver_manager==3.7.1 \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index b3c3a66f..92b16fab 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,11 @@ import os +import platform from unittest import mock import pytest from selenium import webdriver from selenium.webdriver import DesiredCapabilities +from webdriver_manager.chrome import ChromeDriverManager @pytest.fixture @@ -14,9 +16,17 @@ def driver(): options = webdriver.ChromeOptions() options.headless = True capabilities = DesiredCapabilities.CHROME - capabilities['goog:loggingPrefs'] = {"browser": "ALL"} + capabilities["goog:loggingPrefs"] = {"browser": "ALL"} - driver = webdriver.Chrome(options=options, desired_capabilities=capabilities, service_log_path=os.path.devnull) + if platform.system() == "Windows": + options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe" + + driver = webdriver.Chrome( + ChromeDriverManager().install(), + options=options, + desired_capabilities=capabilities, + service_log_path=os.path.devnull, + ) # Firefox doesn't currently supported pulling JavaScript console logs, which we currently scan to affirm that # JS/Python can communicate in some places. So for now, we can't really use firefox/geckodriver during testing. diff --git a/tests/integration/test_examples.py b/tests/integration/test_examples.py index 63119ef7..ca1556f8 100644 --- a/tests/integration/test_examples.py +++ b/tests/integration/test_examples.py @@ -1,4 +1,5 @@ import os +import time from tempfile import TemporaryDirectory, NamedTemporaryFile from selenium import webdriver @@ -47,6 +48,7 @@ def test_04_file_access(driver: webdriver.Remote): with TemporaryDirectory() as temp_dir, NamedTemporaryFile(dir=temp_dir) as temp_file: driver.find_element_by_id('input-box').clear() driver.find_element_by_id('input-box').send_keys(temp_dir) + time.sleep(0.5) driver.find_element_by_css_selector('button').click() assert driver.find_element_by_id('file-name').text == os.path.basename(temp_file.name) diff --git a/tests/utils.py b/tests/utils.py index 1fdd8f8a..ff14d473 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,5 +1,7 @@ import contextlib import os +import sys +import platform import subprocess import tempfile import time @@ -8,15 +10,30 @@ import psutil # Path to the test data folder. -TEST_DATA_DIR = Path(__file__).parent / 'data' +TEST_DATA_DIR = Path(__file__).parent / "data" def get_process_listening_port(proc): - psutil_proc = psutil.Process(proc.pid) - while not any(conn.status == 'LISTEN' for conn in psutil_proc.connections()): - time.sleep(0.01) - - conn = next(filter(lambda conn: conn.status == 'LISTEN', psutil_proc.connections())) + conn = None + if platform.system() == "Windows": + current_process = psutil.Process(proc.pid) + children = [] + while children == []: + time.sleep(0.01) + children = current_process.children(recursive=True) + if (3, 6) <= sys.version_info < (3, 7): + children = [current_process] + for child in children: + while child.connections() == [] and not any(conn.status == "LISTEN" for conn in child.connections()): + time.sleep(0.01) + + conn = next(filter(lambda conn: conn.status == "LISTEN", child.connections())) + else: + psutil_proc = psutil.Process(proc.pid) + while not any(conn.status == "LISTEN" for conn in psutil_proc.connections()): + time.sleep(0.01) + + conn = next(filter(lambda conn: conn.status == "LISTEN", psutil_proc.connections())) return conn.laddr.port @@ -40,8 +57,10 @@ def get_eel_server(example_py, start_html): import {os.path.splitext(os.path.basename(example_py))[0]} """) - - proc = subprocess.Popen(['python', test.name], cwd=os.path.dirname(example_py)) + proc = subprocess.Popen( + [sys.executable, test.name], + cwd=os.path.dirname(example_py), + ) eel_port = get_process_listening_port(proc) yield f"http://localhost:{eel_port}/{start_html}" diff --git a/tox.ini b/tox.ini index fe783da7..fefe2470 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py36,py37,py38,py39,py310 [pytest] -timeout = 5 +timeout = 30 [gh-actions] python = @@ -17,5 +17,5 @@ deps = -r requirements-test.txt commands = # this ugly hack is here because: # https://github.com/tox-dev/tox/issues/149 - pip install -q -r {toxinidir}/requirements-test.txt - {envpython} -m pytest {posargs} + pip install -q -r '{toxinidir}'/requirements-test.txt + '{envpython}' -m pytest {posargs} \ No newline at end of file