[java][bidi]: add getData, addDataCollector and removeDataCollector commands#16336
[java][bidi]: add getData, addDataCollector and removeDataCollector commands#16336navin772 wants to merge 17 commits intoSeleniumHQ:trunkfrom
getData, addDataCollector and removeDataCollector commands#16336Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
| } | ||
|
|
||
| @Test | ||
| @NeedsFreshDriver |
There was a problem hiding this comment.
Why can't the test reuse the driver? Is this a BiDi limitation?
There was a problem hiding this comment.
I added it since other tests were using it too, I will check if its strictly required or not.
There was a problem hiding this comment.
@diemol 3 tests fail when @NeedsFreshDriver is removed from all the tests, 2 auth ones and 1 data collector that was added.
Should I remove it for other tests? It does reduce the test execution time by a lot (45sec -> 14sec)
There was a problem hiding this comment.
We need to be able to clear handlers to reuse drivers
|
So, data collection doesn't make sense outside the context of an interception. You have to pass a request id to get the data, which is only accessible from a handler. I think this should all be private API. When you register a handler you specify if you need the body, and that method registers the collector and manages it in the background. |
@titusfortner should we overload the event handlers to something like this and manage the collector inside the event handler?: public void onBeforeRequestSent(Consumer<BeforeRequestSent> consumer, boolean captureBody)Also, will this be applicable to only these events:
|
There was a problem hiding this comment.
Pull request overview
This PR implements three BiDi network data collection commands following the W3C WebDriver BiDi specification: addDataCollector, removeDataCollector, and getData. These commands enable collecting and retrieving network request/response body data.
Changes:
- Add three network data collection methods to the Network module with proper result mapping
- Implement parameter classes (AddDataCollectorParameters, GetDataParameters) with fluent builder pattern
- Add DataType enum to specify request or response data collection
- Provide comprehensive test coverage for all new functionality including edge cases
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Network.java | Adds addDataCollector, removeDataCollector, and getData methods with proper BiDi command mapping and JSON result parsing |
| AddDataCollectorParameters.java | Parameter builder for configuring data collectors with support for data types, max size, collector type, and contexts |
| DataType.java | Enum defining REQUEST and RESPONSE data types for network data collection |
| GetDataParameters.java | Parameter builder for retrieving collected network data with support for collector ID and disown flag |
| NetworkCommandsTest.java | Comprehensive test suite covering various scenarios including collector lifecycle, data retrieval, disown behavior, and request/response data collection |
| private List<String> userContexts; | ||
|
|
||
| public AddDataCollectorParameters(List<DataType> dataTypes, long maxEncodedDataSize) { | ||
| Require.nonNull("Data types", dataTypes); |
There was a problem hiding this comment.
The constructor should validate that the dataTypes list is not empty. According to the W3C BiDi spec, dataTypes is a required parameter and must contain at least one element. An empty list would result in invalid BiDi command parameters. Consider adding validation similar to other parameter classes in the codebase.
| Require.nonNull("Data types", dataTypes); | |
| Require.nonNull("Data types", dataTypes); | |
| if (dataTypes.isEmpty()) { | |
| throw new IllegalArgumentException("Data types must not be empty"); | |
| } |
| jsonInput.skipValue(); | ||
| } | ||
| } | ||
| jsonInput.endObject(); |
| jsonInput -> { | ||
| Map<String, Object> result = jsonInput.read(Map.class); | ||
| return (String) result.get("collector"); |
| public Map<String, Object> toMap() { | ||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put("dataTypes", dataTypes); | ||
| map.put("maxEncodedDataSize", maxEncodedDataSize); | ||
|
|
||
| if (collectorType != null) { | ||
| map.put("collectorType", collectorType); | ||
| } | ||
|
|
||
| if (contexts != null && !contexts.isEmpty()) { | ||
| map.put("contexts", contexts); | ||
| } | ||
|
|
||
| if (userContexts != null && !userContexts.isEmpty()) { | ||
| map.put("userContexts", userContexts); | ||
| } |
|
|
||
| if (collectorType != null) { | ||
| map.put("collectorType", collectorType); | ||
| } | ||
|
|
User description
🔗 Related Issues
💥 What does this PR do?
Adds
getData,addDataCollectorandremoveDataCollectorcommands as in BiDi spec:🔧 Implementation Notes
💡 Additional Considerations
🔄 Types of changes
PR Type
Enhancement
Description
Add BiDi network data collection commands per W3C spec
Implement
addDataCollector,removeDataCollector, andgetDatamethodsCreate parameter classes for data collection configuration
Add comprehensive test coverage for all new functionality
Diagram Walkthrough
File Walkthrough
Network.java
Add network data collection methodsjava/src/org/openqa/selenium/bidi/module/Network.java
addDataCollector,removeDataCollector,getDatagetDatacommand responseAddDataCollectorParameters.java
Create AddDataCollectorParameters classjava/src/org/openqa/selenium/bidi/network/AddDataCollectorParameters.java
addDataCollectorcommandDataType.java
Add DataType enumjava/src/org/openqa/selenium/bidi/network/DataType.java
GetDataParameters.java
Create GetDataParameters classjava/src/org/openqa/selenium/bidi/network/GetDataParameters.java
getDatacommandNetworkCommandsTest.java
Add data collection command testsjava/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java