Repository navigation
feat(network): support network mocking on Firefox via WebDriver BiDi … - #199
Conversation
|
Thanks @PUSHPAK-JAISWAL, the BiDi-first / CDP-fallback design looks right. Before merge:
|
…og handler errors at WARNING
|
Changelog placement: Entries moved under a new Unreleased section; dropped reference to removing pinned CDP version since fallback still uses CDP v153 classes. |
What & why
Closes #196
networkMock().stub(...)previously worked exclusively on Chrome and Edge via CDP (Fetch.enable). On Firefox, stubs were silently ignored becausedriver instanceof ChromiumDriverevaluated tofalse, causing tests relying on mocked APIs to produce false positives or fail incorrectly.This PR wires up WebDriver BiDi network interception (
org.openqa.selenium.bidi.module.Network) under the hood when the driver implementsHasBiDi(including Firefox and BiDi-enabled Chromium). If BiDi is unavailable or unconfigured (such as Chrome sessions without a BiDi WebSocket), it cleanly falls back to CDP forChromiumDriver. Unsupported drivers (such as Safari) log a warning and continue without breaking.Key changes:
org.openqa.selenium.bidi.module.NetworkwithBEFORE_REQUEST_SENTinterception phase.BytesValue, content-type header, and delays.bidiNetwork.continueRequest(...)and ignored unblocked events.clear()to remove BiDi intercepts, close BiDi network listeners, and disable CDP fetch sessions.StubBuilderfor inspection while preserving the entire existing fluent API contract.NetworkMockTestcovering BiDi matching/non-matching/delay/clear, CDP fallback on BiDi exception, direct CDP path, unsupported browser warnings, null driver safety, and cross-browser consistency (sameStubTest_passesOnChromeAndFirefox).CHANGELOG.mdanddocs-site/docs/changelog.md.Type of change
Checklist
mvn test: 823 passed, 0 failures, 0 skipped)NetworkMockTest)@SeleniumBootApipublic APIs (or a major version bump is justified below)docs-site/)Notes for reviewers
networkMock().stub(...),returnJson(...),returnBody(...),returnStatus(...),delay(...), andclear()retain their exact signatures and behavior.HasBiDiare given preference for BiDi interception. IfbidiFactory.create(driver)throws (such asBiDiException: Check if this browser version supports BiDi and if the 'webSocketUrl: true' capability is set), it catches the error and cleanly falls back to CDP forChromiumDriver.BiDiNetworkFactoryhook (bidiFactory = Network::newby default) so the entire BiDi lifecycle, request interception, header/body construction, delay, and teardown can be verified with Mockito without spinning up real browser sessions.