mirror of
https://git.zavage.net/Zavage-Software/wabot.git
synced 2026-07-22 13:36:08 -06:00
test: external WebDriver server mode (persist + ephemeral)
This commit is contained in:
parent
2dd4d8c13c
commit
7e24d3445d
58
tests/integration/test_external_server.py
Normal file
58
tests/integration/test_external_server.py
Normal file
@ -0,0 +1,58 @@
|
||||
"""host= mode: wabot connects to a WebDriver server it does not manage."""
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
import wabot
|
||||
from wabot.hosts import service_alive
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def external_chromedriver():
|
||||
binary = shutil.which("chromedriver")
|
||||
if binary is None:
|
||||
pytest.skip("chromedriver not on PATH")
|
||||
proc = subprocess.Popen(
|
||||
[binary, "--port=19515"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
url = "http://127.0.0.1:19515"
|
||||
deadline = time.monotonic() + 15
|
||||
while time.monotonic() < deadline and not service_alive(url):
|
||||
time.sleep(0.2)
|
||||
assert service_alive(url), "chromedriver never came up"
|
||||
yield url
|
||||
proc.terminate()
|
||||
proc.wait(timeout=10)
|
||||
|
||||
|
||||
def test_persistent_session_on_external_host(external_chromedriver, site_url, store):
|
||||
bot = wabot.browser(
|
||||
session="ext", browser="chromium", host=external_chromedriver,
|
||||
headless=True, pacing=wabot.NoPacing(), store=store,
|
||||
)
|
||||
bot.driver.get(f"{site_url}/welcome.html")
|
||||
record = store.get("ext")
|
||||
assert record.executor_url == external_chromedriver
|
||||
assert record.service_pid is None # not ours to kill
|
||||
|
||||
# same process, second browser() call: must reattach, not create
|
||||
bot2 = wabot.browser(session="ext", store=store, pacing=wabot.NoPacing())
|
||||
assert bot2.driver.session_id == record.session_id
|
||||
assert bot2.driver.current_url == f"{site_url}/welcome.html"
|
||||
|
||||
bot2.driver.quit()
|
||||
store.remove("ext")
|
||||
|
||||
|
||||
def test_ephemeral_on_external_host(external_chromedriver, site_url, store):
|
||||
bot = wabot.browser(
|
||||
host=external_chromedriver, browser="chromium",
|
||||
headless=True, pacing=wabot.NoPacing(), store=store,
|
||||
)
|
||||
bot.driver.get(f"{site_url}/welcome.html")
|
||||
assert store.names() == [] # session=None never persists
|
||||
bot.driver.quit()
|
||||
Loading…
Reference in New Issue
Block a user