GithubHelp home page GithubHelp logo

playwright-advanced-har's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

playwright-advanced-har's Issues

add a round-robin scoring function

Goal

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.

usage:

    await advancedRouteFromHAR(/api/, {
        matcher: baseMatcher({
            scoring: roundRobin
        })
    });

Intercepting requests to influence HAR lookups, or conditionally enriching responses

First of all, thank you for this library.

The API I'm trying to mock has the following behaviour:

  1. An initial POST to the BE passes generated tempIds for each entity
  2. The BE accepts the tempIds and echos them back in the response
  3. The BE also echos back fixedIds at the same time, and on subsequent responses
  4. The BE will NOT echo back tempIds on subsequent responses

I wouldn't be asking here if the solution was as easy as creating deterministic tempIds 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:

  1. Use INTERCEPT_req to rewrite the tempIds and make them deterministic so that future HAR playback will pick up the right stored mocks
  2. Configure playwright-advanced-har to exclude all tempIds during recording, but use INTERCEPT_req to conditionally enrich INTERCEPT_res with the tempIds the FE sends

Hope this is reasonably clear, and thanks in advance for any advice!

minimal mode

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

add REST scoring function

Goal

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.

usage:

    await advancedRouteFromHAR(/\/(api)|(bff)\//, {
        matcher: baseMatcher({
            scoring: restScoring
        })
    });

When using a customMatcher, the HAR request postData stored in _file is not loading.

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.

Referencing external json-file from HAR-file does not work

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!

How to test it?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.