microsoft / microsoft/playwright
[Feature] Allow regex URL matching in HAR
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
**Currently** [the HAR replay matches URL and HTTP method strictly according to the docs](https://playwright.dev/docs/mock#replaying-from-har:~:text=HAR%20replay%20matches%20URL%20and%20HTTP%20method%20strictly.).
This prevents me from easily replacing my existing network mocks with HAR mocks
Here is what I mean
Let's say I have an API `api/v1/fruits` that takes in a query parameter `color`
The following mocks the API so that the response is mocked for all calls, **regardless of what the query parameter is**
```javascript
await page.route('*/**/api/v1/fruits**', async route => {
```
I would like to use HAR to do the same, but I cannot without manually editing the JSON file.
HAR will create a JSON file for **each URL**. Meaning if the test runs with `api/v1/fruits?color=red` then it will create the mock for **only** the query parameter `color=red`, and not `color=yellow` or `color=green`.
Currently I need to go into the JSON file, copy-paste the existing URL responses, and replace the query parameters. All manually :(
---
**Ideally** if there was a configuration to allow URL pattern matching instead of strict, that would help my use case a lot.
Could we have this as a feature please?
Contributor guide
Research direction
Start with the HAR replay documentation linked in the issue and the page.route entry point used in the example, then trace how strict URL matching handles query parameters. Done means HAR replay can accept a URL pattern so one recorded response covers varying values such as red, yellow, and green without manually editing the JSON file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100