fix(interception): Properly handle binary response data in WebDriverInterception#14360
Merged
christian-bromann merged 2 commits intowebdriverio:mainfrom Apr 2, 2025
Merged
Conversation
added 2 commits
April 1, 2025 19:37
…nterception - Modified WebDriverInterception to correctly store and retrieve binary response data via getBinaryResponse() - Updated parseOverwrite to properly encode binary data in base64 format - Enhanced clear() to reset responseBodies map alongside calls array - Improved #handleResponseStarted to store binary response data - Added test case verifying binary response handling and clearing - Maintained compatibility with existing string/JSON response handling
eslint-plugin-wdio
@wdio/allure-reporter
@wdio/browser-runner
@wdio/appium-service
@wdio/browserstack-service
@wdio/cli
@wdio/concise-reporter
@wdio/config
@wdio/cucumber-framework
@wdio/dot-reporter
@wdio/firefox-profile-service
@wdio/globals
@wdio/jasmine-framework
@wdio/json-reporter
@wdio/junit-reporter
@wdio/lighthouse-service
@wdio/local-runner
@wdio/logger
@wdio/mocha-framework
@wdio/protocols
@wdio/repl
@wdio/reporter
@wdio/runner
@wdio/sauce-service
@wdio/shared-store-service
@wdio/smoke-test-cjs-service
@wdio/smoke-test-reporter
@wdio/smoke-test-service
@wdio/spec-reporter
@wdio/static-server-service
@wdio/sumologic-reporter
@wdio/testingbot-service
@wdio/types
@wdio/utils
@wdio/webdriver-mock-service
webdriver
webdriverio
commit: |
3 tasks
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
This pull request addresses the issue reported in #11709, where binary response bodies were not being properly handled. The changes introduce a new method,
getBinaryResponse, which allows retrieval of raw binary data from a mock response byrequest ID. Additionally, therespondmethod has been updated to correctly store binary response bodies, and theclearmethod appropriately resets the stored response bodies. Tests have been added to verify the fix.The goal is to ensure that binary data (e.g., Buffer objects) can be mocked and retrieved accurately in network interception scenarios, fixing the bug where such responses were not accessible or handled correctly.
Types of changes
Checklist
Backport Request
v9and doesn't need to be back-ported#XXXXXFurther comments
Key Changes:
getBinaryResponseMethod: This addition allows users to retrieve raw binary data from the#responseBodiesmap. It decodes base64-encoded content into aBuffer, manages nested encodings, and gracefully returnsnullwhen no binary data is present.respondLogic: Updated the method to store response bodies in#responseBodieswhenever an overwrite is applied, ensuring binary data is preserved and accessible for later retrieval.clearMethod: The method now resets the#responseBodiesmap alongside other mock state, guaranteeing predictable resets for reliable testing workflows.index.test.tssimulates a binary response, validates retrieval viagetBinaryResponse, and confirmsclearwipes the slate clean.Alternatives Explored:
Direct Binary Storage Without Base64: One idea was to store binary data raw, skipping base64 encoding. However, this clashed with the WebDriver Bidi protocol’s expectation of encoded payloads, risking compatibility issues, so I stuck with the protocol’s conventions.
Reviewers: @webdriverio/project-committers