Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7e7d54b
Test changes
doug-benn Oct 21, 2022
b4726bf
Chrome driver install
doug-benn Nov 15, 2022
5d208b0
Runs Locals
doug-benn Nov 15, 2022
26fc0d1
webdriver_manager 3.7.1
doug-benn Nov 16, 2022
1409716
running tests in tests folder
doug-benn Nov 16, 2022
2b76844
basetempdir
doug-benn Nov 16, 2022
6f25f88
pytest config
doug-benn Nov 16, 2022
8911d4e
pytest config
doug-benn Nov 16, 2022
25f4f19
-m
doug-benn Nov 16, 2022
2bb9242
pip install -e .
doug-benn Nov 16, 2022
3338747
Action edit
doug-benn Nov 16, 2022
55d4797
tox config
doug-benn Nov 16, 2022
c4d2f7d
python setup.py install
doug-benn Nov 16, 2022
606dc74
install_command = pip install -U {opts} {packages}
doug-benn Nov 16, 2022
1aa8405
update packages
doug-benn Nov 16, 2022
ad9808f
version change
doug-benn Nov 16, 2022
313aedb
version change
doug-benn Nov 16, 2022
eb80554
commands change
doug-benn Nov 16, 2022
c524494
no spaces?
doug-benn Nov 16, 2022
e89761a
more spaces
doug-benn Nov 16, 2022
b7f2f45
tox -vv
doug-benn Nov 19, 2022
94d0013
--
doug-benn Nov 19, 2022
dc374d0
sleep
doug-benn Nov 19, 2022
c15af0f
sleep
doug-benn Nov 19, 2022
4ebe94f
Working Windows Tests
doug-benn Nov 20, 2022
90e3e0e
Linux fix
doug-benn Nov 20, 2022
cebadce
linux fix
doug-benn Nov 20, 2022
fc2d94d
shell = False
doug-benn Nov 20, 2022
ae5e581
Fixing files access test on Windows
doug-benn Nov 20, 2022
83e8ad2
python 3.6
doug-benn Nov 20, 2022
5858a64
Clean up
doug-benn Nov 20, 2022
a489b9d
3.6 Fix
doug-benn Nov 20, 2022
26c80ca
Clean up
doug-benn Nov 20, 2022
7f3ea59
Clean up for Pull Request
doug-benn Nov 20, 2022
47f9d99
Test.yml set to on push master
doug-benn Nov 20, 2022
04ed29e
Just an extra second?
doug-benn Nov 20, 2022
349e652
Retest
doug-benn Nov 20, 2022
0a0cf9b
Setting test.yml to main
doug-benn Nov 20, 2022
8ff199f
ignore Drivers folder
doug-benn Dec 9, 2022
a1ab4c8
Windows No Chrome Fix
doug-benn Oct 21, 2022
fdf55c6
Github actions and fixing Linux tests
doug-benn Nov 16, 2022
16a171d
Clean up
doug-benn Nov 20, 2022
93895f3
ignore Drivers folder
doug-benn Dec 9, 2022
e533525
Merge branch 'Windows-Tests' of https://github.com/doug-benn/Eel into…
doug-benn Dec 9, 2022
7aafb90
Merge branch 'Windows-Tests' into Fixing-Tests
doug-benn Dec 9, 2022
8c771a9
Merge pull request #1 from doug-benn/Fixing-Tests
doug-benn Dec 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: Test Eel

on:
push:
branches: [ master ]
branches:
[master]
# - '*'
# - '!master'

pull_request:

jobs:
Expand All @@ -12,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']

steps:
- name: Checkout repository
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__pycache__
dist
Drivers
build
Eel.egg-info
.tmp
Expand Down
6 changes: 6 additions & 0 deletions Drivers/.wdm/drivers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"win32_chromedriver_107.0.5304_for_107.0.5304": {
"timestamp": "15/11/2022",
"binary_path": ".\\\\Drivers\\.wdm\\drivers\\chromedriver\\win32\\107.0.5304\\chromedriver.exe"
}
}
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions requirements-meta.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tox>=3.15.2,<4.0.0
tox>=3.27.1,<4.0.0
tox-pyenv==1.1.0
tox-gh-actions==1.3.0
virtualenv>=16.7.10
tox-gh-actions==2.11.0
virtualenv>=16.7.10
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +18,11 @@ def driver():
capabilities = DesiredCapabilities.CHROME
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)
#driver = webdriver.Chrome()

# 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.
Expand Down
54 changes: 36 additions & 18 deletions tests/integration/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
from tempfile import TemporaryDirectory, NamedTemporaryFile

from selenium import webdriver
Expand All @@ -10,52 +11,69 @@


def test_01_hello_world(driver):
with get_eel_server('examples/01 - hello_world/hello.py', 'hello.html') as eel_url:
with get_eel_server("examples/01 - hello_world/hello.py", "hello.html") as eel_url:
driver.get(eel_url)
assert driver.title == "Hello, World!"

console_logs = get_console_logs(driver, minimum_logs=2)
assert "Hello from Javascript World!" in console_logs[0]['message']
assert "Hello from Python World!" in console_logs[1]['message']
assert "Hello from Javascript World!" in console_logs[0]["message"]
assert "Hello from Python World!" in console_logs[1]["message"]


def test_02_callbacks(driver):
with get_eel_server('examples/02 - callbacks/callbacks.py', 'callbacks.html') as eel_url:
with get_eel_server(
"examples/02 - callbacks/callbacks.py", "callbacks.html"
) as eel_url:
driver.get(eel_url)
assert driver.title == "Callbacks Demo"

console_logs = get_console_logs(driver, minimum_logs=1)
assert "Got this from Python:" in console_logs[0]['message']
assert "callbacks.html" in console_logs[0]['message']
assert "Got this from Python:" in console_logs[0]["message"]
assert "callbacks.html" in console_logs[0]["message"]


def test_03_callbacks(driver):
with get_eel_server('examples/03 - sync_callbacks/sync_callbacks.py', 'sync_callbacks.html') as eel_url:
with get_eel_server(
"examples/03 - sync_callbacks/sync_callbacks.py", "sync_callbacks.html"
) as eel_url:
driver.get(eel_url)
assert driver.title == "Synchronous callbacks"

console_logs = get_console_logs(driver, minimum_logs=1)
assert "Got this from Python:" in console_logs[0]['message']
assert "callbacks.html" in console_logs[0]['message']
assert "Got this from Python:" in console_logs[0]["message"]
assert "callbacks.html" in console_logs[0]["message"]


def test_04_file_access(driver: webdriver.Remote):
with get_eel_server('examples/04 - file_access/file_access.py', 'file_access.html') as eel_url:
with get_eel_server(
"examples/04 - file_access/file_access.py", "file_access.html"
) as eel_url:
driver.get(eel_url)
assert driver.title == "Eel Demo"

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)
driver.find_element_by_css_selector('button').click()
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(1)
driver.find_element_by_css_selector("button").click()

assert driver.find_element_by_id('file-name').text == os.path.basename(temp_file.name)
assert driver.find_element_by_id("file-name").text == os.path.basename(
temp_file.name
)


def test_06_jinja_templates(driver: webdriver.Remote):
with get_eel_server('examples/06 - jinja_templates/hello.py', 'templates/hello.html') as eel_url:
with get_eel_server(
"examples/06 - jinja_templates/hello.py", "templates/hello.html"
) as eel_url:
driver.get(eel_url)
assert driver.title == "Hello, World!"

driver.find_element_by_css_selector('a').click()
WebDriverWait(driver, 2.0).until(expected_conditions.presence_of_element_located((By.XPATH, '//h1[text()="This is page 2"]')))
driver.find_element_by_css_selector("a").click()
WebDriverWait(driver, 2.0).until(
expected_conditions.presence_of_element_located(
(By.XPATH, '//h1[text()="This is page 2"]')
)
)
59 changes: 47 additions & 12 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
import contextlib
import os
import sys
import platform
import subprocess

# Hack for python 3.6
subprocess._cleanup = lambda: None
import tempfile
import time
from pathlib import Path

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 = None
if platform.system() == "Windows":
current_process = psutil.Process(proc.pid)
children = current_process.children(recursive=True)
if children == []:
children = [current_process]
for child in children:
if child.connections() != []:
while 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())
)

conn = next(filter(lambda conn: conn.status == 'LISTEN', psutil_proc.connections()))
return conn.laddr.port


Expand All @@ -26,22 +49,34 @@ def get_eel_server(example_py, start_html):
test = None

try:
with tempfile.NamedTemporaryFile(mode='w', dir=os.path.dirname(example_py), delete=False) as test:
with tempfile.NamedTemporaryFile(
mode="w", dir=os.path.dirname(example_py), delete=False
) as test:
# We want to run the examples unmodified to keep the test as realistic as possible, but all of the examples
# want to launch browsers, which won't be supported in CI. The below script will configure eel to open on
# a random port and not open a browser, before importing the Python example file - which will then
# do the rest of the set up and start the eel server. This is definitely hacky, and means we can't
# test mode/port settings for examples ... but this is OK for now.
test.write(f"""
test.write(
f"""
import eel

eel._start_args['mode'] = None
eel._start_args['port'] = 0

import {os.path.splitext(os.path.basename(example_py))[0]}
""")

proc = subprocess.Popen(['python', test.name], cwd=os.path.dirname(example_py))
"""
)
if platform.system() == "Windows":
proc = subprocess.Popen(
[sys.executable, test.name],
cwd=os.path.dirname(example_py),
)
else:
proc = subprocess.Popen(
["python", test.name], cwd=os.path.dirname(example_py)
)
time.sleep(1)
eel_port = get_process_listening_port(proc)

yield f"http://localhost:{eel_port}/{start_html}"
Expand All @@ -57,10 +92,10 @@ def get_eel_server(example_py, start_html):


def get_console_logs(driver, minimum_logs=0):
console_logs = driver.get_log('browser')
console_logs = driver.get_log("browser")

while len(console_logs) < minimum_logs:
console_logs += driver.get_log('browser')
console_logs += driver.get_log("browser")
time.sleep(0.1)

return console_logs
9 changes: 5 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
envlist = py36,py37,py38,py39,py310

[pytest]
timeout = 5
pythonpath = . eel
timeout = 60

[gh-actions]
python =
Expand All @@ -14,8 +15,8 @@ python =

[testenv]
deps = -r requirements-test.txt
commands =
commands = '{envpython}' -m pytest {posargs}
# 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}