karate - Karate Server feature file cannot access variables in karate-config.js file
问题描述
I am working on API testing project and have incorporated Karate to do so. Now my requirement is to create a server which will respond to the endpoint.All this is done but my requirement is to access variables defined in karate-config file in Server feature. I am unable to do so.
For example: Feature: Sample server
Scenario: pathMatches('\variablevalue) ** methodIs('get')
- def response = default_env
Note: default_env is a variable in karate-config.js file and holds some default value.
解决方案
很好的问题,我们故意不想将这个karate-config.js
概念与空手道服务器端混为一谈。
通常,当您通过 API 实例化模拟服务器时,您可以传递 JavaMap
并且所有键值将最终作为空手道变量。
但这里有个技巧,你可以在Background
* call read('classpath:karate-config.js')
这将产生您正在寻找的完全相同的效果!请让我知道这是否有效,我将确保在文档中对此进行更新。
请注意,如果您只需要一些种子数据,则可以使用 JSON:
* def cats = read('cats.json')
推荐阅读
- c# - c#串口数据混合接近0读数
- google-apps-script - 如何解决“无法读取 null 的属性 'getName'”错误?
- locking - Geode DUnit 虚拟机间通信
- javascript - 将平面表转换为层次结构
- r - 在 R 中用 grep 排除变量
- raspberry-pi - 在运行 Manjaro 和 X11 的 Raspberry Pi3 上无法旋转(默认)屏幕
- react-native - react-native-navigation createMaterialBottomTabNavigator 从 tabBar 隐藏选项卡
- javascript - QF 测试如何获取 JButton 背景颜色?
- javascript - jquery 数据表无法通过 ajax 发布请求正常工作?
- matlab - 在 Matlab 中根据文件名加载 .csv 文件