mirror of https://github.com/pyodide/pyodide.git
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
|
"""
|
||
|
Various common utilities for testing.
|
||
|
"""
|
||
|
|
||
|
import pathlib
|
||
|
|
||
|
import pytest
|
||
|
|
||
|
|
||
|
TEST_PATH = pathlib.Path(__file__).parents[0].resolve()
|
||
|
BUILD_PATH = TEST_PATH / '..' / 'build'
|
||
|
|
||
|
|
||
|
class PyodideInited:
|
||
|
def __call__(self, driver):
|
||
|
inited = driver.execute_script("return pyodide.runPython")
|
||
|
return inited is not None
|
||
|
|
||
|
|
||
|
class SeleniumWrapper:
|
||
|
def __init__(self):
|
||
|
from selenium.webdriver import Firefox
|
||
|
from selenium.webdriver.firefox.options import Options
|
||
|
from selenium.webdriver.support.wait import WebDriverWait
|
||
|
|
||
|
options = Options()
|
||
|
options.add_argument('-headless')
|
||
|
driver = Firefox(executable_path='geckodriver', firefox_options=options)
|
||
|
wait = WebDriverWait(driver, timeout=20)
|
||
|
driver.get((BUILD_PATH / "test.html").as_uri())
|
||
|
wait.until(PyodideInited())
|
||
|
|
||
|
self.driver = driver
|
||
|
|
||
|
@property
|
||
|
def logs(self):
|
||
|
return self.driver.execute_script("return window.logs")
|
||
|
|
||
|
def run(self, code):
|
||
|
return self.driver.execute_script(
|
||
|
'return pyodide.runPython({!r})'.format(code))
|
||
|
|
||
|
@property
|
||
|
def urls(self):
|
||
|
for handle in self.driver.window_handles:
|
||
|
self.driver.switch_to.window(handle)
|
||
|
yield self.driver.current_url
|
||
|
|
||
|
|
||
|
@pytest.fixture
|
||
|
def selenium():
|
||
|
return SeleniumWrapper()
|