noamgaash / playwright-advanced-har Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
when the user makes several requests to the same resource, replay those request in the same order as it was recorded.
for example:
GET api/count
returns {"count": 1}
GET api/count
returns {"count": 2}
GET api/count
returns {"count": 3}
when recording and when replaying, we want to achieve the same behaviour.
await advancedRouteFromHAR(/api/, {
matcher: baseMatcher({
scoring: roundRobin
})
});
First of all, thank you for this library.
The API I'm trying to mock has the following behaviour:
tempId
s for each entitytempId
s and echos them back in the responsefixedId
s at the same time, and on subsequent responsestempId
s on subsequent responsesI wouldn't be asking here if the solution was as easy as creating deterministic tempId
s in the FE, which would almost certainly solve my issue, but I'm trying the following approaches.
Given:
stateDiagram-v2
direction LR
FE --> request
request --> HAR
HAR --> response
response --> FE
I want to try and perform the following intercepts for my HARs:
stateDiagram-v2
direction LR
FE --> request
request --> INTERCEPT_req
INTERCEPT_req --> HAR
HAR --> response
response --> INTERCEPT_res
INTERCEPT_res --> FE
Essentially I want to either:
INTERCEPT_req
to rewrite the tempId
s and make them deterministic so that future HAR playback will pick up the right stored mocksplaywright-advanced-har
to exclude all tempId
s during recording, but use INTERCEPT_req
to conditionally enrich INTERCEPT_res
with the tempId
s the FE sendsHope this is reasonably clear, and thanks in advance for any advice!
I think that we have a problem with the "minimal" mode - it captures a lot of irrelevant data, including:
startedDateTime
time
httpVersion
cookies
headersSize
bodySize
cache
timings
I think that Playwright also has this problem, but it would be nice if we had a way to work around it
when the user makes several requests to the same resource, we want to distinguish state altering requests from read only request, and replay the requests in the right order.
for example:
GET api/status
returns {"count": 123}
GET api/status
returns {"count": 123}
POST api/status
with body {"count": 456}
returns {"saved": true}
GET api/status
returns {"count": 456}
when recording and when replaying, we want to achieve the same behavior.
await advancedRouteFromHAR(/\/(api)|(bff)\//, {
matcher: baseMatcher({
scoring: restScoring
})
});
If a request is stored in HAR and only utilizes postData._file for storage, it cannot be accessed when using a customMatcher.
For example:
A HAR file:
"log": {
"entries": [
{
"request": {
"method": "POST",
"url": "https://dev-cb-patch-monitor.quid.com/cb/api/2/runSearches",
"headers": [],
"queryString": [],
"postData": {
"mimeType": "application/x-www-form-urlencoded",
"text": "",
"params": [],
"_file": "80cfc9ca2ceb7ebb0da70500393558554ef433da.dat"
}
80cfc9ca2ceb7ebb0da70500393558554ef433da.dat :
product=%22SEARCH%22&searchInfo=false
When using customMatcher:
matcher: (request, entry) => {
entry.request.postData.params; // This is null
entry.request.postData.text; // This is null
},
How to access entry's postData?
When recording the HAR, only certain requests are saved to _file without any information in text or params. The workaround for this is to use updateContent: 'embed' to avoid it.
Hi!
First of all - great timing introducing this tool just when I needed it :) I needed to remove a uuid search param and was struggling with all kinds of bad workarounds before I found your repo.
I just have one issue and that is that I do not get the response content when it is referenced from an external json-file.
Does not work:
"content": {
"size": -1,
"mimeType": "application/json; charset=utf-8",
"_file": "24634189ca062af1d89f1ed15ac3ae60ca869596.json"
},
Works:
"content": {
"size": -1,
"mimeType": "application/json; charset=utf-8",
"text": "{\"key\" : \"value\"}"
},
This is kind of a blocker since the advancedRouteFromHAR("./file.har", {update: true}) generates a bunch of json files referenced inside the har-file.
I really would appreciate your help with this!
On test.spec.ts
I've tried to test the record and play mechanism, yet failed to do so. When the Playwright team test the routeFromHar
function they do something quite sophisticated with contextFactory
, and I don't have the capacity to learn what's going on over there.
Anyway, I'd really like to have the ability to have a test that records a Har file, and then uses it
Any help would be appreciated
the utf-8
encoding isn't always good.
when dealing with images, it's not working
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.