问题
How to build dynamic urls in Karate feature file? I tried something like this and didn't work.
Feature: PMS API Status Check
Background:
* url baseUrl
* def spirit = 'SANRS'
Scenario: Get guest details.
Given path "'#(spirit)'/reservation/all"
Url is not evaluating to SANRS and goes as spirit. Also how do I change write the json response to a file. I see we can read the file using read(fileName) but did not see examples for writing to a file.
回答1:
The '#(foo)'
notation applies only to JSON, XML or the right-hand-side of a match statement.
Please use it like a normal JS expression:
Given path spirit, 'reservation', 'all'
Please do look at the documentation and examples !
Yes, there is no example for writing to a file, because this is not recommended for tests. If you really want to do this - just write a custom Java or JavaScript function, refer to the docs for "Calling Java".
来源:https://stackoverflow.com/questions/47515805/building-dynamic-urls-in-karate-and-writing-json-output-to-a-file