karate - Karate.print 不打印实际内容
问题描述
我正在尝试这个
Scenario: FORMAT
* def word = '{\n \"enterpriseEventEnvelope\" : {\n \"eventId\" : \"61322555-c5e0-434c-ade0-96f8ca4\",\n \"eventOccurrenceTimestamp\" : \"2018-09-30T02:00:00\",\n \"eventDataQuality\" : {\n \"com.sample.EventDataQualityAttributesRecord\" : {\n \"executedRuleSetId\" : \"fcf79a09-d6c2-4fda-b8b7-b12c44191\",\n \"failedRuleIds\" : {\n \"array\" : [ ]\n },\n \"errorRuleIds\" : {\n \"array\" : [ ]\n }\n }\n }\n },\n \"domainPayload\" : {\n \"employeeId\" : \"TMB5\",\n \"supportType\" : \"Bench\",\n \"roleEndDate\" : 1577836800000,\n \"specialtyProgramName\" : \"\",\n \"contractorStatus\" : \"\",\n \"lastChangeDate\" : 1609390800000,\n \"lastChangeBy\" : \"FYC9\"\n }\n}'
* def word1 = (word.replace(/(\r\n|\n|\r)/gm,""))
* def word2 = (word1.replace(/\s+/g," "))
* print word2 . #this prints fine
* print karate.pretty(wrod2) # doesn't print pretty for mat.
* print karate.pretty(word2..domainPayload) #this prints nothing
解决方案
编辑:在示例清楚之后。
您错过的是,在进行字符串替换后,您会得到一个字符串,而不是 JSON。您需要转换回 JSON,这在空手道中非常容易。
只需添加这一行:
* json word2 = word2
* karate.log(word2) ## this will log pretty
* print word2 ## this will log pretty
* print 'debug:', word2 ## this will log pretty
* karate.log("debug: " + word2) ## this will NOT log pretty
* karate.log("debug:", word2) ## this will log pretty
之后的一切都会如你所愿。
推荐阅读
- c++ - 默认情况下停用预编译的标头 Visual Studio C++
- tensorflow - mobilenet迁移学习后验证准确率低
- r - read.csv() 中的非英文字符 - R
- c - printf() 精度
- apache-nifi - Apache Nifi中PutHBaseRecord中具有多个字段的行标识符
- amazon-web-services - “kubectl”未从我的本地 Windows 工作站连接到 aws EKS 集群
- javascript - 如何在 Jasmine 的单元测试中模拟 super.ngOnInit()?如何在基类/父类方法上创建间谍以仅涵盖派生/子类代码?
- postgresql - 使用 Codeigniter 3.1.10 将数组和 JSON 插入 PostgreSQL 时出错
- javascript - 快速回复 Facebook Messenger 问题
- c# - C# 中的单行 if-else