6

I'm trying to print value on console but I don't see any value

snippet of code

And prepresp = response.event.txn_count
Then print 'count is : ',  response.event.txn_count
Then print 'count is : ',  prepresp
bummi
  • 27,123
  • 14
  • 62
  • 101
Shiva Krishna
  • 103
  • 1
  • 2
  • 5

3 Answers3

6

your code seems to be missing with 'def' keyword for defining 'prepresp'

And def prepresp = response.event.txn_count 
Then print 'count is : ', response.event.txn_count 
Then print 'count is : ', prepresp

This should work

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
  • com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property ['EXPR$0'] in path $ but found 'net.minidev.json.JSONArray'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'. at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:69) at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62) at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:53) at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:61 – Shiva Krishna May 14 '19 at 05:45
  • o/p from postman [ { "EXPR$0": 479085608 } ] Scenario: Get count Given url 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' And request {body} When method POST Then status 200 And mtlprepresp = response.EXPR$0 Then print 'count is : ', response.EXPR$0 Then print 'count is : ', mtlprepresp – Shiva Krishna May 14 '19 at 05:48
  • 2
    @ShivaKrishna your response is an array so do this: `* def count = response[0].EXPR$0` – Peter Thomas May 14 '19 at 05:59
  • Thanks @Peter Thomas it worked Also is they any reference on how to pass jwt in tests can you pls let me know if there's any documentation on that – Shiva Krishna May 14 '19 at 06:14
  • Done - Accepted now pls any reference on how to pass jwt in tests – Shiva Krishna May 14 '19 at 07:36
  • 1
    @ShivaKrishna here you go: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/jwt/jwt.feature – Peter Thomas May 14 '19 at 09:58
2

You should use karate.log(response) for logging on the console.

vimuth
  • 5,064
  • 33
  • 79
  • 116
1

The print action should print to the HTML page which is provided in the console after the tests run.

Luke D.
  • 53
  • 6
  • can you give an example – Shiva Krishna May 14 '19 at 05:18
  • --------------------------------------------------------- feature: classpath:mock/contract/payment-service.feature scenarios: 1 | passed: 1 | failed: 0 | time: 0.1510 --------------------------------------------------------- HTML report: (paste into browser to view) | Karate version: 1.0.0 file:/home/username/git/karate/karate-demo/target/surefire-reports/mock.contract.payment-service.html --------------------------------------------------------- After the test runs you should see something like this in the console. – Luke D. May 14 '19 at 05:31
  • Take the file and paste it into a browser. This provides a little more verbose debugging for the tests. Another option is to run the test via the karate.jar UI. [link](https://github.com/intuit/karate/wiki/Karate-UI) – Luke D. May 14 '19 at 05:33
  • Also the def keyword is missing in the And def prepresp = response.event.txn_count – Luke D. May 14 '19 at 05:35