microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
64.21k stars 3.48k forks source link

[Feature]: Ability to consume matching entries using routeFromHAR #30754

Open SimonSikstrom opened 2 months ago

SimonSikstrom commented 2 months ago

🚀 Feature Request

Add ability to consume each matching entry using routeFromHAR, then it would be possible to have a recorded .har with multiple matching entries without needing to switch .har in the middle of the tests. Possible solution to #18288

Example

Have a recorded .har with a new server state after reload.

Replay .har using a consume (or similar) flag for routeFromHAR.

await context.routeFromHAR(path, {
    consume: true
  });

Implementation POC https://github.com/microsoft/playwright/compare/main...SimonSikstrom:playwright:consume-har-entry-18288

Motivation

Its not possible to handle subsequent requests using har replay, see #18288 .

My proposal is to add ability to consume each matching entry with routeFromHAR, then it would be possible to have a recorded .har with many matching entries that could return different results for subsequent calls.

yury-s commented 2 months ago

The reason we haven't taken any action on this is that we didn't want a sub par solution. If we improve the replay from har logic we'd like its functionality to y comparable to Web Page Replay. If your proposed change aligns with this standard, we would be open to reviewing and accepting PRs.