How to print values in console in karate tests
Asked Answered
S

3

7

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
Secede answered 14/5, 2019 at 4:47 Comment(0)
J
7

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

Judgment answered 14/5, 2019 at 5:28 Comment(6)
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:61Secede
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 : ', mtlpreprespSecede
@ShivaKrishna your response is an array so do this: * def count = response[0].EXPR$0Deficit
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 thatSecede
Done - Accepted now pls any reference on how to pass jwt in testsSecede
@ShivaKrishna here you go: github.com/intuit/karate/blob/master/karate-demo/src/test/java/…Deficit
M
3

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

Metatherian answered 9/8, 2022 at 18:35 Comment(0)
E
1

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

Evadnee answered 14/5, 2019 at 5:6 Comment(4)
can you give an exampleSecede
--------------------------------------------------------- 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.Evadnee
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. linkEvadnee
Also the def keyword is missing in the And def prepresp = response.event.txn_countEvadnee

© 2022 - 2024 — McMap. All rights reserved.