mirror of
https://git.zavage.net/Zavage-Software/wabot.git
synced 2026-07-21 13:06:08 -06:00
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
from selenium.common.exceptions import WebDriverException
|
|
|
|
from wabot.hosts import ReattachingRemote, attach, build_options
|
|
|
|
|
|
class TestReattachingRemote:
|
|
def test_adopts_session_id_without_creating_a_session(self):
|
|
# constructing against a closed port (127.0.0.1:1) proves no HTTP happens
|
|
# until the first command
|
|
driver = ReattachingRemote(
|
|
"http://127.0.0.1:1", "saved-session-id", options=build_options("chromium")
|
|
)
|
|
# base __init__ resets session_id to None BEFORE start_session runs;
|
|
# our override must still win
|
|
assert driver.session_id == "saved-session-id"
|
|
assert isinstance(driver.caps, dict)
|
|
|
|
def test_works_for_firefox_options_too(self):
|
|
driver = ReattachingRemote(
|
|
"http://127.0.0.1:1", "sid", options=build_options("firefox")
|
|
)
|
|
assert driver.session_id == "sid"
|
|
|
|
|
|
class TestAttach:
|
|
def test_returns_driver_when_probe_succeeds(self, monkeypatch):
|
|
monkeypatch.setattr(
|
|
ReattachingRemote, "current_url", property(lambda self: "http://example.com")
|
|
)
|
|
driver = attach("http://127.0.0.1:1", "sid", "chromium")
|
|
assert driver is not None
|
|
assert driver.session_id == "sid"
|
|
|
|
def test_returns_none_when_session_is_dead(self, monkeypatch):
|
|
def boom(self):
|
|
raise WebDriverException("invalid session id")
|
|
|
|
monkeypatch.setattr(ReattachingRemote, "current_url", property(boom))
|
|
assert attach("http://127.0.0.1:1", "sid", "chromium") is None
|
|
|
|
def test_returns_none_when_server_is_unreachable(self):
|
|
# no server on port 1: connection refused is immediate; attach must not raise
|
|
assert attach("http://127.0.0.1:1", "sid", "chromium") is None
|
|
|
|
def test_dead_session_closes_executor(self, monkeypatch):
|
|
from selenium.webdriver.remote.remote_connection import RemoteConnection
|
|
|
|
closed = []
|
|
monkeypatch.setattr(RemoteConnection, "close", lambda self: closed.append(1))
|
|
|
|
def boom(self):
|
|
raise WebDriverException("invalid session id")
|
|
|
|
monkeypatch.setattr(ReattachingRemote, "current_url", property(boom))
|
|
assert attach("http://127.0.0.1:1", "sid", "chromium") is None
|
|
assert closed == [1] # executor was closed, not leaked
|