diff --git a/bidi-test.py b/bidi-test.py index fed7b20..60dc44e 100755 --- a/bidi-test.py +++ b/bidi-test.py @@ -5,6 +5,7 @@ import logging import os import threading import time +from pathlib import Path from typing import Any import bidi @@ -58,6 +59,18 @@ class Browser: asyncio.run_coroutine_threadsafe(self.driver.start_session(), self.loop).result() + test_functions = Path("test-functions.js").read_text() + self.bidi("script.addPreloadScript", functionDeclaration=f"() => {{ {test_functions} }}") + + try: + sizzle_js = (Path(__file__).parent / "node_modules/sizzle/dist/sizzle.js").read_text() + # HACK: sizzle tracks document and when we switch frames, it sees the old document + # although we execute it in different context. + sizzle_js = sizzle_js.replace('context = context || document;', 'context = context || window.document;') + self.bidi("script.addPreloadScript", functionDeclaration=f"() => {{ {sizzle_js} }}") + except FileNotFoundError: + pass + def close(self): asyncio.run_coroutine_threadsafe(self.driver.close(), self.loop).result() self.loop.call_soon_threadsafe(self.loop.stop) @@ -196,6 +209,7 @@ try: b.wait_text("#super-user-indicator", "Limited access") b.switch_to_frame("cockpit1:localhost/system") + b.wait_visible(".pf-v5-c-alert:contains('Web console is running in limited access mode.')") b.wait_in_text(".system-configuration", "Join domain") b.switch_to_top() diff --git a/bidi.py b/bidi.py index 3fa5c9e..bf4be8b 100755 --- a/bidi.py +++ b/bidi.py @@ -127,9 +127,6 @@ class WebdriverBidi: "log.entryAdded", "browsingContext.domContentLoaded", ]) - test_functions = Path("test-functions.js").read_text() - await self.bidi("script.addPreloadScript", functionDeclaration=f"() => {{ {test_functions} }}") - # wait for browser to initialize default context for _ in range(10): realms = (await self.bidi("script.getRealms"))["realms"] @@ -193,7 +190,8 @@ class WebdriverBidi: """Send a Webdriver BiDi command and return the JSON response""" payload = json.dumps({"id": self.last_id, "method": method, "params": params}) - log_proto.debug("ws ← %r", payload) + # avoid log spam for preload scripts + log_proto.debug("ws ← %r", method if method == "script.addPreloadScript" else payload) await self.ws.send_str(payload) future = asyncio.get_event_loop().create_future() self.pending_commands[self.last_id] = future diff --git a/package.json b/package.json index b08cfd1..996f4ec 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "jed": "1.1.1", "qunit": "2.21.1", "sass": "1.77.8", + "sizzle": "2.3.10", "stylelint": "16.7.0", "stylelint-config-recommended-scss": "14.0.0", "stylelint-config-standard": "36.0.1", diff --git a/test-functions.js b/test-functions.js index 633e3fe..9b5b19a 100644 --- a/test-functions.js +++ b/test-functions.js @@ -1,8 +1,4 @@ window.ph_select = function(sel) { - if (!window.Sizzle) { - return Array.from(document.querySelectorAll(sel)); - } - if (sel.includes(":contains(")) { if (!window.Sizzle) { throw new Error("Using ':contains' when window.Sizzle is not available.");