Skip to content

fix(interception): Properly handle binary response data in WebDriverInterception#14360

Merged
christian-bromann merged 2 commits intowebdriverio:mainfrom
Norva-bugged:fix/binary-handle
Apr 2, 2025
Merged

fix(interception): Properly handle binary response data in WebDriverInterception#14360
christian-bromann merged 2 commits intowebdriverio:mainfrom
Norva-bugged:fix/binary-handle

Conversation

@Norva-bugged
Copy link
Member

@Norva-bugged Norva-bugged commented Apr 1, 2025

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 by request ID. Additionally, the respond method has been updated to correctly store binary response bodies, and the clear method 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

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Key Changes:

  • New getBinaryResponse Method: This addition allows users to retrieve raw binary data from the #responseBodies map. It decodes base64-encoded content into a Buffer, manages nested encodings, and gracefully returns null when no binary data is present.
  • Refined respond Logic: Updated the method to store response bodies in #responseBodies whenever an overwrite is applied, ensuring binary data is preserved and accessible for later retrieval.
  • Improved clear Method: The method now resets the #responseBodies map alongside other mock state, guaranteeing predictable resets for reliable testing workflows.
  • Comprehensive Testing: A new test case, handles binary response and clear, in index.test.ts simulates a binary response, validates retrieval via getBinaryResponse, and confirms clear wipes 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

Norva-bugged 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
@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 1, 2025

Open in StackBlitz

eslint-plugin-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@14360

@wdio/allure-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@14360

@wdio/browser-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@14360

@wdio/appium-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@14360

@wdio/browserstack-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@14360

@wdio/cli

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@14360

@wdio/concise-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@14360

@wdio/config

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@14360

@wdio/cucumber-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@14360

@wdio/dot-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@14360

@wdio/firefox-profile-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@14360

@wdio/globals

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@14360

@wdio/jasmine-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@14360

@wdio/json-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@14360

@wdio/junit-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@14360

@wdio/lighthouse-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@14360

@wdio/local-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@14360

@wdio/logger

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@14360

@wdio/mocha-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@14360

@wdio/protocols

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@14360

@wdio/repl

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@14360

@wdio/reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@14360

@wdio/runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@14360

@wdio/sauce-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@14360

@wdio/shared-store-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@14360

@wdio/smoke-test-cjs-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@14360

@wdio/smoke-test-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@14360

@wdio/smoke-test-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@14360

@wdio/spec-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@14360

@wdio/static-server-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@14360

@wdio/sumologic-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@14360

@wdio/testingbot-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@14360

@wdio/types

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@14360

@wdio/utils

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@14360

@wdio/webdriver-mock-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@14360

webdriver

npm i https://pkg.pr.new/webdriverio/webdriverio/webdriver@14360

webdriverio

npm i https://pkg.pr.new/webdriverio/webdriverio@14360

commit: 08d830c

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Great job!

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Apr 2, 2025
@christian-bromann christian-bromann merged commit a451961 into webdriverio:main Apr 2, 2025
46 checks passed
@Norva-bugged Norva-bugged deleted the fix/binary-handle branch April 3, 2025 09:48
@Norva-bugged Norva-bugged restored the fix/binary-handle branch April 10, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants