question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid response from karate.read inside a js function

See original GitHub issue

Java8 and karate 0.6.1 & 0.6.2

Given the test.json file content

{ "foo":"bar"}

When calling the following function from a feature file

function() {
    var test = karate.read('classpath:api/test.json');
    karate.log(test);
    karate.log(JSON.stringify(test));
}

then the value of test is undefined

but if called in a feature like:

* def test = call('classpath:api/test.json')
* print test

then the value of test is the json structure

I have tried many combinations but it never reads the json correctly

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ptrthomascommented, Aug 5, 2021

@justindwyer6 and most likely you are looking for karate.call(). I am still not sure what you are trying and whether a “feature type” works in JS - so we may still need that way to replicate

1reaction
ptrthomascommented, Aug 5, 2021

@justindwyer6 can’t tell from this. follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid response from karate.read inside a js function #267
For context, I'm trying to make a more simple, readable way to call some helper functions, like * run_helper("create", "client") , but the...
Read more >
Using call read within a js function - karate - Stack Overflow
So the idea is to reset the 'myId' variable everytime to null, check if null which will be true, then call the js...
Read more >
Karate UI
A very powerful variation of waitUntil() takes a full-fledged JavaScript function as the argument. This can loop until any user-defined condition and can...
Read more >
Step-2: Variables, karate-config, API requests, Assertions - Kloia
This is a simple JS function. You can define the variables in the config as a JSON format (“key: value” structure) and use...
Read more >
Calling Custom Java Code in Karate API Tests
This code simply writes our token to config.properties file by using write method. Then you can read the value by using read method....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found