-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[java][BiDi] implement emulation #16070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the BiDi emulation module for Java, specifically focusing on geolocation override functionality. The implementation follows the W3C WebDriver BiDi emulation specification and provides a comprehensive API for controlling geolocation behavior in browser contexts.
- Adds core emulation classes including
Emulation
,GeolocationCoordinates
, and parameter classes - Implements geolocation override functionality with proper validation and error handling
- Creates extensive test coverage for both browsing contexts and user contexts
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
java/src/org/openqa/selenium/bidi/emulation/Emulation.java |
Main emulation module class providing BiDi command execution |
java/src/org/openqa/selenium/bidi/emulation/GeolocationCoordinates.java |
Geolocation data class with coordinate validation |
java/src/org/openqa/selenium/bidi/emulation/SetGeolocationOverrideParameters.java |
Parameter class for geolocation override commands |
java/src/org/openqa/selenium/bidi/emulation/GeolocationPositionError.java |
Error representation for geolocation failures |
java/test/org/openqa/selenium/bidi/emulation/EmulationTest.java |
Comprehensive test suite covering various emulation scenarios |
java/src/org/openqa/selenium/bidi/emulation/BUILD.bazel |
Build configuration for emulation package |
java/test/org/openqa/selenium/bidi/emulation/BUILD.bazel |
Test build configuration |
java/src/org/openqa/selenium/remote/BUILD.bazel |
Updated remote package dependencies |
java/src/org/openqa/selenium/bidi/module/BUILD.bazel |
Updated module package dependencies |
private final List<String> contexts; | ||
private final List<String> userContexts; | ||
|
||
SetGeolocationOverrideParameters( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor has package-private visibility, which may limit API usability. Consider making it public to allow external instantiation of parameters.
SetGeolocationOverrideParameters( | |
public SetGeolocationOverrideParameters( |
Copilot uses AI. Check for mistakes.
import java.util.Map; | ||
|
||
public class GeolocationPositionError { | ||
String type = "positionUnavailable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field should be private and final since it's not intended to be modified. Consider adding 'private final' modifiers.
String type = "positionUnavailable"; | |
private final String type = "positionUnavailable"; |
Copilot uses AI. Check for mistakes.
BrowsingContext context2 = new BrowsingContext(driver, WindowType.TAB); | ||
|
||
GeolocationCoordinates coords = | ||
new GeolocationCoordinates(45.5, -122.4194, 10.0, null, null, null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor call has 7 arguments but the GeolocationCoordinates constructor only accepts 6 parameters (excluding the 7-parameter constructor). This will cause a compilation error.
new GeolocationCoordinates(45.5, -122.4194, 10.0, null, null, null, null); | |
new GeolocationCoordinates(45.5, -122.4194, 10.0, null, null, null); |
Copilot uses AI. Check for mistakes.
driver, new CreateContextParameters(WindowType.TAB).userContext(userContext2)); | ||
|
||
GeolocationCoordinates coords = | ||
new GeolocationCoordinates(45.5, -122.4194, 10.0, null, null, null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor call has 7 arguments but the GeolocationCoordinates constructor only accepts 6 parameters (excluding the 7-parameter constructor). This will cause a compilation error.
new GeolocationCoordinates(45.5, -122.4194, 10.0, null, null, null, null); | |
new GeolocationCoordinates(45.5, -122.4194, 10.0, null, null, null); |
Copilot uses AI. Check for mistakes.
assert !r.containsKey("error"); | ||
|
||
double latitude = ((Number) r.get("latitude")).doubleValue(); | ||
double longitude = ((Number) r.get("longitude")).doubleValue(); | ||
double accuracy = ((Number) r.get("accuracy")).doubleValue(); | ||
|
||
assert abs(latitude - coords.getLatitude()) < 0.0001; | ||
assert abs(longitude - coords.getLongitude()) < 0.0001; | ||
assert abs(accuracy - coords.getAccuracy()) < 0.0001; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using assert statements in tests is not recommended. Consider using JUnit assertions like assertFalse() for better error reporting and test reliability.
assert !r.containsKey("error"); | |
double latitude = ((Number) r.get("latitude")).doubleValue(); | |
double longitude = ((Number) r.get("longitude")).doubleValue(); | |
double accuracy = ((Number) r.get("accuracy")).doubleValue(); | |
assert abs(latitude - coords.getLatitude()) < 0.0001; | |
assert abs(longitude - coords.getLongitude()) < 0.0001; | |
assert abs(accuracy - coords.getAccuracy()) < 0.0001; | |
assertFalse(r.containsKey("error")); | |
double latitude = ((Number) r.get("latitude")).doubleValue(); | |
double longitude = ((Number) r.get("longitude")).doubleValue(); | |
double accuracy = ((Number) r.get("accuracy")).doubleValue(); | |
assertTrue(abs(latitude - coords.getLatitude()) < 0.0001); | |
assertTrue(abs(longitude - coords.getLongitude()) < 0.0001); | |
assertTrue(abs(accuracy - coords.getAccuracy()) < 0.0001); |
Copilot uses AI. Check for mistakes.
assert !r.containsKey("error"); | ||
|
||
double latitude = ((Number) r.get("latitude")).doubleValue(); | ||
double longitude = ((Number) r.get("longitude")).doubleValue(); | ||
double accuracy = ((Number) r.get("accuracy")).doubleValue(); | ||
|
||
assert abs(latitude - coords.getLatitude()) < 0.0001; | ||
assert abs(longitude - coords.getLongitude()) < 0.0001; | ||
assert abs(accuracy - coords.getAccuracy()) < 0.0001; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using assert statements in tests is not recommended. Consider using JUnit assertions like assertTrue() or assertEquals() with delta for better error reporting.
assert !r.containsKey("error"); | |
double latitude = ((Number) r.get("latitude")).doubleValue(); | |
double longitude = ((Number) r.get("longitude")).doubleValue(); | |
double accuracy = ((Number) r.get("accuracy")).doubleValue(); | |
assert abs(latitude - coords.getLatitude()) < 0.0001; | |
assert abs(longitude - coords.getLongitude()) < 0.0001; | |
assert abs(accuracy - coords.getAccuracy()) < 0.0001; | |
assertTrue(!r.containsKey("error")); | |
double latitude = ((Number) r.get("latitude")).doubleValue(); | |
double longitude = ((Number) r.get("longitude")).doubleValue(); | |
double accuracy = ((Number) r.get("accuracy")).doubleValue(); | |
assertEquals(coords.getLatitude(), latitude, 0.0001); | |
assertEquals(coords.getLongitude(), longitude, 0.0001); | |
assertEquals(coords.getAccuracy(), accuracy, 0.0001); |
Copilot uses AI. Check for mistakes.
e5300bf
to
7be9945
Compare
User description
🔗 Related Issues
💥 What does this PR do?
Implements emulation BiDi spec in Java
🔧 Implementation Notes
Uses same BiDi approach which is used for other modules
💡 Additional Considerations
🔄 Types of changes
PR Type
Enhancement
Description
Implements BiDi emulation module for geolocation override
Adds GeolocationCoordinates class with validation
Creates comprehensive test suite for emulation functionality
Updates build configuration for new emulation package
Diagram Walkthrough
File Walkthrough