Search code examples
ui-automationwiremockxcuitestwiremock-standalone

When is a second priority request trigged on Wiremock?


I'm new to Wiremock and I'm not sure how priority works. I am able to trigger a request I've labeled as first priority but I'm not able to trigger a request I've labeled as second priority. It always just triggers the request that is first priority. Anyone know how to trigger second priority requests?


Solution

  • Setting priorities allows you to specify what happens when more than one stub can match a particular request.

    1 is the highest priority, 10 the lowest and the default is 5.

    Generally a good way to use priorities is to have high priority stubs with specific matches for particular test cases you need to run, plus lower priority stubs with broader matches for development/exploratory testing.

    So e.g. you might have a set of stubs a priority 5 that match URLs like /v1/contacts/12354, /v1/contacts/23456 etc. plus a stub at priority 8 that matches on a URL regex of /v1/contacts/[0-9]+.

    The stubs with specific IDs in the URL paths (12345 and 23456) would be used to return the data you need for particular test cases, and the lower-priority generic stub would return something valid regardless of the ID used.