feat: session reattach via ReattachingRemote (adopts saved session id)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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):
|
||||
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
|
||||
Reference in New Issue
Block a user