[py][bidi]: implement bidi module - emulation
User description
🔗 Related Issues
💥 What does this PR do?
Adds support for the emulation module in python bindings - https://w3c.github.io/webdriver-bidi/#module-emulation
🔧 Implementation Notes
Usage:
-
From
contexts:from selenium.webdriver.common.bidi.emulation import GeolocationCoordinates context_id = driver.current_window_handle coords = GeolocationCoordinates(45.5, -122.4194, accuracy=10.0) driver.emulation.set_geolocation_override(coordinates=coords, contexts=[context_id]) -
From
user_contexts:from selenium.webdriver.common.bidi.emulation import GeolocationCoordinates user_context = driver.browser.create_user_context() context_id = driver.browsing_context.create(type=WindowTypes.TAB, user_context=user_context) driver.switch_to.window(context_id) coords = GeolocationCoordinates(45.5, -122.4194, accuracy=10.0, altitude=100.2, altitude_accuracy=5.0, heading=183.2, speed=10.0) driver.emulation.set_geolocation_override(coordinates=coords, user_contexts=[user_context])
[!IMPORTANT] Either
user_contextsorcontextsshould be passed, both cannot coexist.
💡 Additional Considerations
The tests need the BiDi permissions module to grant the geolocation permission in order to fetch them.
[!NOTE] Currently, when the
Errorparameter is passed, it is returning an errorinvalid argument: Invalid input in "coordinates, hence the test is commented out for now. It is fixed in chrome canary.
🔄 Types of changes
- New feature (non-breaking change which adds functionality and tests!)
PR Type
Enhancement
Description
• Implement BiDi emulation module for Python bindings • Add geolocation override functionality with coordinates support • Include comprehensive test coverage for contexts and user contexts • Support multiple browsing contexts and user contexts
Changes walkthrough 📝
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
| ||||
| Tests |
|
Need help?
Type /help how to ...in the comments thread for any questions about Qodo Merge usage.Check out the documentation for more information.
The tests require geolocation permission access which can be done once #15830 is merged.
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
|
🎫 Ticket compliance analysis ❌ 5678 - Not compliant Non-compliant requirements: • Fix ChromeDriver connection failure error that occurs after first instance • Resolve "ConnectFailure (Connection refused)" error for subsequent ChromeDriver instances • Ensure proper ChromeDriver instantiation without connection issues 1234 - Not compliant Non-compliant requirements: • Fix JavaScript execution in link href on click() method for Selenium 2.48+ • Ensure JavaScript alerts are triggered when clicking links with JavaScript in href • Restore functionality that worked in Selenium 2.47.1 but broke in 2.48.0/2.48.2 |
| ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewValidation Logic
0.0 <= heading < 360.0. This may be inconsistent with geolocation standards where 360.0 degrees should be equivalent to 0.0 degrees. |
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Remove invalid context closeThis line attempts to close py/test/selenium/webdriver/common/bidi_emulation_tests.py [120]
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies a bug in the test | Medium |
| ||
@cgoldberg can this be merged?
yea, I think so.. the CI failure seems unrelated.
@navin772 What did you think about my comment?
@shbenzer which comment? I think I am missing something here.
would this get_geolocation() function be useful to the end user as a method in their high-level api?
this one
would this get_geolocation() function be useful to the end user as a method in their high-level api?
this one
Surprisingly, I can't see this comment anywhere even now.
Anyways, I assume from get_geolocation() you mean the get_browser_geolocation() helper method in the tests.
Yes, we can have that as high-level but which namespace should it be in - driver.emulation or something else since Emulation module contains some other commands also.
We can decide on this and I will open another PR to add it.
Anyways, I assume from
get_geolocation()you mean theget_browser_geolocation()helper method in the tests. Yes, we can have that as high-level but which namespace should it be in -driver.emulationor something else since Emulation module contains some other commands also.We can decide on this and I will open another PR to add it.
Odd that you can’t see it…. But either way, I would think driver.emulation would be fine.