building dynamic urls in Karate and writing json output to a file

自作多情 提交于 2019-12-13 17:36:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!