|
| 1 | +import os |
| 2 | +from tempfile import TemporaryDirectory, NamedTemporaryFile |
| 3 | + |
| 4 | +from selenium import webdriver |
| 5 | +from selenium.webdriver.common.by import By |
| 6 | +from selenium.webdriver.support import expected_conditions |
| 7 | +from selenium.webdriver.support.wait import WebDriverWait |
| 8 | + |
| 9 | +from tests.utils import get_eel_server, get_console_logs |
| 10 | + |
| 11 | + |
| 12 | +def test_01_hello_world(driver): |
| 13 | + with get_eel_server('examples/01 - hello_world/hello.py', 'hello.html') as eel_url: |
| 14 | + driver.get(eel_url) |
| 15 | + assert driver.title == "Hello, World!" |
| 16 | + |
| 17 | + console_logs = get_console_logs(driver, minimum_logs=2) |
| 18 | + assert "Hello from Javascript World!" in console_logs[0]['message'] |
| 19 | + assert "Hello from Python World!" in console_logs[1]['message'] |
| 20 | + |
| 21 | + |
| 22 | +def test_02_callbacks(driver): |
| 23 | + with get_eel_server('examples/02 - callbacks/callbacks.py', 'callbacks.html') as eel_url: |
| 24 | + driver.get(eel_url) |
| 25 | + assert driver.title == "Callbacks Demo" |
| 26 | + |
| 27 | + console_logs = get_console_logs(driver, minimum_logs=1) |
| 28 | + assert "Got this from Python:" in console_logs[0]['message'] |
| 29 | + assert "callbacks.html" in console_logs[0]['message'] |
| 30 | + |
| 31 | + |
| 32 | +def test_03_callbacks(driver): |
| 33 | + with get_eel_server('examples/03 - sync_callbacks/sync_callbacks.py', 'sync_callbacks.html') as eel_url: |
| 34 | + driver.get(eel_url) |
| 35 | + assert driver.title == "Synchronous callbacks" |
| 36 | + |
| 37 | + console_logs = get_console_logs(driver, minimum_logs=1) |
| 38 | + assert "Got this from Python:" in console_logs[0]['message'] |
| 39 | + assert "callbacks.html" in console_logs[0]['message'] |
| 40 | + |
| 41 | + |
| 42 | +def test_04_file_access(driver: webdriver.Remote): |
| 43 | + with get_eel_server('examples/04 - file_access/file_access.py', 'file_access.html') as eel_url: |
| 44 | + driver.get(eel_url) |
| 45 | + assert driver.title == "Eel Demo" |
| 46 | + |
| 47 | + with TemporaryDirectory() as temp_dir, NamedTemporaryFile(dir=temp_dir) as temp_file: |
| 48 | + driver.find_element_by_id('input-box').clear() |
| 49 | + driver.find_element_by_id('input-box').send_keys(temp_dir) |
| 50 | + driver.find_element_by_css_selector('button').click() |
| 51 | + |
| 52 | + assert driver.find_element_by_id('file-name').text == os.path.basename(temp_file.name) |
| 53 | + |
| 54 | + |
| 55 | +def test_06_jinja_templates(driver: webdriver.Remote): |
| 56 | + with get_eel_server('examples/06 - jinja_templates/hello.py', 'templates/hello.html') as eel_url: |
| 57 | + driver.get(eel_url) |
| 58 | + assert driver.title == "Hello, World!" |
| 59 | + |
| 60 | + driver.find_element_by_css_selector('a').click() |
| 61 | + WebDriverWait(driver, 2.0).until(expected_conditions.presence_of_element_located((By.XPATH, '//h1[text()="This is page 2"]'))) |
0 commit comments