Kumar112
Kumar112

Reputation: 224

Karate.print not printing the actual content

I am trying this

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

Upvotes: 1

Views: 949

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

EDIT: after the example was made clear.

What you missed is that after doing a string replace, you end up with a string, not JSON. You need to convert back to JSON which is very easy in Karate.

Just add this line:

* 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

And everything after that will work as you expect.

Upvotes: 1

Related Questions