Skip to content

Conversation

navin772
Copy link
Member

@navin772 navin772 commented Aug 25, 2025

User description

🔗 Related Issues

💥 What does this PR do?

Fixes and enables some tests in bidi_network_tests.py for chrome and edge.

🔧 Implementation Notes

  1. We can say that it is a bug in chromium, if we navigate to a page using a classic command like driver.get() (which we were doing in our tests), continue request won't work, it is working when we navigate using BiDi commands - driver.browsing_context.navigate. At the time of network PR, we didn't have the browsing context module so it was skipped.
  2. For the auth test, seems like httpbin is not working (TLS issue), swapping it with https://postman-echo.com/basic-auth works well. We can also run a docker container in the CI to avoid dependency on this site - https://hub.docker.com/r/kennethreitz/httpbin/ but I think it will be complex to add it to all workflows.

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)

PR Type

Tests


Description

  • Fix BiDi network tests by using BiDi navigate command

  • Switch from httpbin to postman-echo for auth testing

  • Remove xfail markers for Chrome and Edge tests


Diagram Walkthrough

flowchart LR A["Classic driver.get()"] -- "Replace with" --> B["BiDi navigate command"] C["httpbin.org"] -- "Switch to" --> D["postman-echo.com"] E["Failing tests"] -- "Enable" --> F["Working tests"] 
Loading

File Walkthrough

Relevant files
Tests
bidi_network_tests.py
Fix BiDi network tests navigation                                               

py/test/selenium/webdriver/common/bidi_network_tests.py

  • Replace classic navigation with BiDi browsing_context.navigate()
  • Switch from httpbin to postman-echo for auth testing
  • Remove xfail markers for Chrome and Edge
  • Add ReadinessState import for navigation waiting
+7/-10   

@selenium-ci selenium-ci added the C-py Python Bindings label Aug 25, 2025
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

5678 - Partially compliant

Compliant requirements:

Non-compliant requirements:

  • Investigate and resolve "ConnectFailure" on ChromeDriver instantiation
  • Ensure stable ChromeDriver sessions without repeated connection failures
  • Provide reproducible steps or fixes for the connection refusal

Requires further human verification:

1234 - Partially compliant

Compliant requirements:

Non-compliant requirements:

  • Ensure click() triggers JavaScript in link href in Firefox 2.48
  • Provide validation/tests for JS href execution on click

Requires further human verification:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

In test_continue_with_auth, the variable callback_id is asserted but never defined before assignment; this will raise a NameError or fail the assertion. Ensure callback_id is set from add_auth_handler as intended.

def test_continue_with_auth(driver): callback_id = driver.network.add_auth_handler("postman", "password") assert callback_id is not None, "Request handler not added" driver.browsing_context.navigate( context=driver.current_window_handle, url="https://postman-echo.com/basic-auth", wait=ReadinessState.COMPLETE ) assert "authenticated" in driver.page_source, "Authorization failed"
API Usage

The BiDi navigate call uses context=driver.current_window_handle. Confirm that BiDi browsing_context.navigate expects a browsing context id compatible with current_window_handle; some drivers require driver.bidi_session context ids.

url = pages.url("formPage.html") driver.browsing_context.navigate(context=driver.current_window_handle, url=url, wait=ReadinessState.COMPLETE) assert driver.find_element(By.NAME, "login").is_displayed(), "Request not continued"
Test Fragility

External dependency on postman-echo.com for basic-auth may introduce flakiness. Consider local mock/server or dockerized httpbin as noted in PR description.

driver.browsing_context.navigate( context=driver.current_window_handle, url="https://postman-echo.com/basic-auth", wait=ReadinessState.COMPLETE ) assert "authenticated" in driver.page_source, "Authorization failed"
Copy link
Contributor

qodo-merge-pro bot commented Aug 25, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use correct BiDi context id

Ensure the correct browsing context id is passed. driver.current_window_handle
typically returns a WebDriver window handle, which may not match the BiDi
browsing context id. Use the BiDi-derived context id to avoid navigation failing
silently.

py/test/selenium/webdriver/common/bidi_network_tests.py [78]

-driver.browsing_context.navigate(context=driver.current_window_handle, url=url, wait=ReadinessState.COMPLETE) +context_id = driver.browsing_context.current_context # obtain the BiDi browsing context id from the driver +driver.browsing_context.navigate(context=context_id, url=url, wait=ReadinessState.COMPLETE)
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that driver.current_window_handle might not be the appropriate BiDi context ID, and using a dedicated BiDi property improves the robustness and correctness of the test.

Medium
Assert against correct response

Verify the expected response body for Postman Echo's basic auth endpoint. It
returns a JSON payload with "authenticated": true, not the literal string
"authenticated" in raw HTML. Parse the body or check for the specific JSON key
to prevent false negatives.

py/test/selenium/webdriver/common/bidi_network_tests.py [83-88]

 callback_id = driver.network.add_auth_handler("postman", "password") assert callback_id is not None, "Request handler not added" +context_id = driver.browsing_context.current_context driver.browsing_context.navigate( - context=driver.current_window_handle, url="https://postman-echo.com/basic-auth", wait=ReadinessState.COMPLETE + context=context_id, url="https://postman-echo.com/basic-auth", wait=ReadinessState.COMPLETE ) -assert "authenticated" in driver.page_source, "Authorization failed" +assert '"authenticated": true' in driver.page_source or "authenticated" in driver.find_element(By.TAG_NAME, "body").text, "Authorization failed"
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out the response format of the new endpoint and proposes a more specific assertion, which makes the test more robust and less prone to false positives.

Medium
Learned
best practice
Align assertion with test intent

The final assertion checks driver.network.intercepts, which appears unrelated to
auth handlers and likely a copy-paste error. Update the assertion to verify that
the auth handler was removed, e.g., by checking the auth handlers collection or
by asserting that an authenticated request now fails. This keeps the test name,
intent, and assertions consistent.

py/test/selenium/webdriver/common/bidi_network_tests.py [91-95]

 def test_remove_auth_handler(driver): callback_id = driver.network.add_auth_handler("user", "passwd") assert callback_id is not None, "Request handler not added" driver.network.remove_auth_handler(callback_id) - assert driver.network.intercepts == [], "Intercept not removed" + # Ensure the auth handler is removed; authenticated request should now fail + driver.browsing_context.navigate( + context=driver.current_window_handle, + url="https://postman-echo.com/basic-auth", + wait=ReadinessState.COMPLETE, + ) + assert "authenticated" not in driver.page_source, "Auth handler not removed"
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Fix syntax errors, typos, and naming inconsistencies in code and tests to maintain clarity and prevent confusion.

Low
General
Reduce auth flow flakiness

Add an explicit wait for ReadinessState.COMPLETE is good, but network-level auth
challenges can complete with interactive in some drivers. To avoid flakiness,
consider waiting for either COMPLETE or verifying the page content
post-navigation with a short retry loop.

py/test/selenium/webdriver/common/bidi_network_tests.py [85-87]

+context_id = driver.browsing_context.current_context driver.browsing_context.navigate( - context=driver.current_window_handle, url="https://postman-echo.com/basic-auth", wait=ReadinessState.COMPLETE + context=context_id, url="https://postman-echo.com/basic-auth", wait=ReadinessState.COMPLETE ) +# Fallback verification to reduce flakiness +for _ in range(5): + if '"authenticated": true' in driver.page_source: + break + driver.sleep(0.2) +assert '"authenticated": true' in driver.page_source, "Authorization failed"
  • Apply / Chat
Suggestion importance[1-10]: 4

__

Why: The suggestion proposes adding a retry loop to handle potential flakiness, which could improve test stability, although the existing wait on ReadinessState.COMPLETE should already be sufficient.

Low
  • Update
Copy link
Member

@cgoldberg cgoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@navin772 navin772 merged commit 0754c5a into SeleniumHQ:trunk Aug 26, 2025
4 checks passed
@navin772 navin772 deleted the fix-bidi-network-tests-py branch August 26, 2025 03:54
This was referenced Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants