concept XPath selector in category microservice

appears as: XPath selector, n XPath selector
Testing Microservices with Mountebank

This is an excerpt from Manning's book Testing Microservices with Mountebank.

If you use the XPath selector of //number on this XML document, you get three values: 1, 2, and 3. The predicateGenerators field is smart enough to capture multiple values and save them using a standard predicate array, which requires all results to be present in subsequent requests to match but allows them to be present in any order.

Your virtual response needs to reflect back details of the second account in the request. Those details are specific to your test scenario, but the ID has to match what was sent in the request body. You can use an XPath selector to grab the id attribute of the second account attribute, as shown in the following listing.

Listing 7.14. Using an XPath selector to copy a value from the request to the response
{
  "responses": [{
    "is": {
      "body": "<account><id>$ID</id>...</account>"      #1
    },
    "_behaviors": {
      "copy": [{
        "from": "body",
        "into": "$ID",                                  #2
        "using": {
          "method": "xpath",                            #3
          "selector": "//a:account[2]/@id",             #3
          "ns": {                                       #3
            "a": "https://www.example.com/accounts"     #3
          }                                             #3
        }
      }]
    }
  }]
}