首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Karate.print没有打印实际内容

Karate.print没有打印实际内容
EN

Stack Overflow用户
提问于 2018-09-29 18:41:12
回答 1查看 459关注 0票数 1

我在试这个

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-30 01:36:45

编辑:在说明示例之后。

您忽略的是,在执行字符串替换之后,您将得到一个字符串,而不是JSON。您需要转换回JSON,这在空手道中非常容易。

只需添加这一行:

代码语言:javascript
复制
* 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

之后的一切都会如你所料。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52571429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档