* Builds a fully qualified path using the given set of command parameters. Each * path segment prefixed with ':' will be replaced by the value of the * corresponding parameter. All parameters spliced into the path will be * removed from the parameter map. * @param {string} path The original reso
(path, parameters)
| 557 | * @return {string} The modified path. |
| 558 | */ |
| 559 | function buildPath(path, parameters) { |
| 560 | let pathParameters = path.match(/\/:(\w+)\b/g) |
| 561 | if (pathParameters) { |
| 562 | for (let i = 0; i < pathParameters.length; ++i) { |
| 563 | let key = pathParameters[i].substring(2) // Trim the /: |
| 564 | if (key in parameters) { |
| 565 | let value = parameters[key] |
| 566 | if (webElement.isId(value)) { |
| 567 | // When inserting a WebElement into the URL, only use its ID value, |
| 568 | // not the full JSON. |
| 569 | value = webElement.extractId(value) |
| 570 | } |
| 571 | path = path.replace(pathParameters[i], '/' + value) |
| 572 | delete parameters[key] |
| 573 | } else { |
| 574 | throw new error.InvalidArgumentError('Missing required parameter: ' + key) |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | return path |
| 579 | } |
| 580 | |
| 581 | // PUBLIC API |
| 582 |
no test coverage detected