scala - 通过创建 JSON 对象使用数据生成器的空手道 DSL 返回 null
问题描述
我正在尝试构建一个动态 JSON 对象,为此我正在使用数据生成器,我将 JSON 对象的数据放入其中,并在 .feature 文件中调用该数据生成器。
URL 请求未从数据生成器获取数据并显示为空。可能的原因是什么?
import net.minidev.json.JSONObject;
public class DataGenerator {
public static JSONObject getRandomWF(){
String workflowId = "hello";
String name = "bye";
String description = "descc";
String category = null;
Boolean setnotify = false;
json.put("workflowId", workflowId);
json.put("name", name);
json.put("description", description);
json.put("setnotify", setnotify);
return json;
}
}
.feature 文件如下:
Given path '/workflow/create'
* header Authorization = 'Bearer ' + accessToken
* def dataGenerator = Java.type('DataGenerator')
* def articleRequestBody = read('classpath:examples/users/createworkflow.json')
* set articleRequestBody.workflowId = dataGenerator.getRandomWF().workflowId
* set articleRequestBody.name = dataGenerator.getRandomWF().name
* set articleRequestBody.description = dataGenerator.getRandomWF().description
* set articleRequestBody.setnotify = dataGenerator.getRandomWF().setnotify
And request articleRequestBody
When method Post
Then status 200
下面是createworkflow.json:
{
workflowId : "id workflow"
name : "name workflow"
description : "Desc workflow"
setnotify : true
}
任何有助于了解为什么每个键(workflowId、name、description、setnotify)都为 null 的任何帮助都将不胜感激。
解决方案
您尚未阅读文档:https ://github.com/intuit/karate#calling-java
不要使用JSONObject
返回类型,不管是什么,只使用一个普通的Map
. 或者您可以返回一个字符串并在空手道中进行类型转换:https ://github.com/intuit/karate#type-conversion
推荐阅读
- java - 在 java 中,我的 toString() 没有按预期工作
- java - JodaTime 月底转换
- vba - 从其他工作簿中获取数据 - 在嵌套 if 中未实现目标
- python - 为什么 Python 中的导入函数速度较慢
- java - @ 用 sql 和 java
- c - 回文程序,让用户选择是否要再次执行代码
- android - 从可完成到可观察
- html - 如何在我的 Bootstrap flex 子元素中具有相同的高度?
- jenkins - 是否可以通过静态链接获取触发另一个 Jenkins 作业的用户的名称?
- jquery - 查询没有在 ios 上触发,在 chrome 移动设备中没有响应,但在 pc 中很好