New stub mapping record/playback feature
See original GitHub issueProblem
WireMock’s record feature seems to be one of the most heavily used, and as such it is quite frequently the subject of feature requests. Rather than apply lots of spot fixes for specific cases, I propose re-writing the record feature from scratch, incorporating general solutions to the types of problems expressed here and on the mailing list.
Based on past questions and requests related to the recorder, I’d like to suggest it attempts to achieve the following things:
- Record and playback without having to restart in between.
- Customise output: file naming, request/response headers/body transformation.
- Filter what gets recorded.
- Statefulness - support a succession of responses for the same request (rather than just ignoring subsequent responses as is currently the case)
- Choose target - in memory, persisted, downloaded
- Potential to import from other formats e.g. HAR, RAML (but not necessarily immediate support)
Update It looks like more flexibility in how body patterns are recorded would also be useful. The current behaviour when the request body is JSON is to do a non-strict semantic equality match. Being able to specify the parameters passed to this or override it with e.g. a JSONPath match for a single element would probably be helpful in many cases.
Solution
I propose the following solution based on these objectives:
Snapshot recording - make some requests (that get captured in the request journal) then hit a “capture snapshot” API. This avoids the stop/start problem.
Recording parameters Optional filtering and transformation parameters could be passed into the API call, in addition to a save/download flag. This could include an indication of how to match request bodies.
Use Scenarios for multiple identical requests - when more than one instance of a request is seen, capture each under one scenario so that the progression of responses seen originally is played back.
Recording transformer extension point - expose a Java interface that (similar to ResponseDefinitionTransformer
) supports custom transformations of stub mappings as they’re recorded.
Recording adapter extension point - expose a Java API to the recorder which is sufficiently generic that other formats can be adapted to it e.g. Swagger/RAML or HAR.
Now that it’s possible to add admin API routes, an option would be to implement this as an extension, and therefore incubate in in a separate project.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Looks to be very compatible with the operations I proposed in my pull request last year:
https://github.com/tomakehurst/wiremock/pull/400 Added ability to record a particular request/response repeatedly
so I’m all for this solution.
For those following this issue: I just entered PR #674 to integrate wiremock-snapshot into wiremock