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.

Reading file and embedd file content in JS leads to

See original GitHub issue

This issue was taken from: https://stackoverflow.com/questions/59489470/karate-dsl-how-to-read-token-string-from-arg-and-send-this-string-in-json-re

The following Scenario:

    Scenario: Test to read/write within karate..
        * def fileContent = 'xyz12345'
        * eval  karate.write(karate.get('fileContent'), 'aFile.text'); 
        * def fromFile = read('file:target/aFile.text')

        # This works:
        * match fileContent == fromFile

        * def fromFileEmbeddedInJs = fromFile + ""
        # This fails with error message:  path: $, actual: 'xyz12345', expected: 'java.io.FileInputStream@3114dcf3', reason: not equal
        * match fileContent == fromFileEmbeddedInJs

Results in this error message:

fKarate version: 0.9.5.RC4
======================================================
elapsed:   0.92 | threads:    1 | thread time: 0.03 
features:     1 | ignored:    0 | efficiency: 0.03
scenarios:    1 | passed:     0 | failed: 1
======================================================
failed features:
src.test.groovy.com.github.peterquiel.karate.experiment.karate-syntax-collection: karate-syntax-collection.feature:222 - path: $, actual: 'xyz12345', expected: 'java.io.FileInputStream@3114dcf3', reason: not equal

Same result with 0.9.5.RC5. Tested with latest adopt jdk 12 and 8 version. (log is is from jdk12)

Executed with vs-code karate runner + karate standalone and intellij idea - just mentioned, because there are some groovy type casting issues.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ptrthomascommented, Dec 29, 2019

@peterquiel I made a commit that hopefully puts this discussion to rest, will close the PR

1reaction
ptrthomascommented, Dec 28, 2019

@peterquiel just to make sure I understand because this is a lot of indirection and is confusing to me

where test.foo is { "foo": "bar" }

* def tmp = read('test.foo')
* def bar = { baz: '#(tmp)' }
* print bar

this results in:

[print] {
  "baz": java.io.FileInputStream@4b7dc788
}

but one small change: * json tmp = read('test.foo') results in the expected behavior. what needs to change in karate ? and * string tmp = read('test.foo') would also work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading file contents on the client-side in javascript in various ...
In order to read a file chosen by the user, using a file open dialog, you can use the <input type="file"> tag. You...
Read more >
How to read a local text file using JavaScript? - GeeksforGeeks
FileReader.readAsDataURL(): Reads the contents of the specified input file. The result attribute contains a URL representing the file's data.
Read more >
Read files in JavaScript - web.dev
To read a file, use FileReader , which enables you to read the content of a File object into memory. You can instruct...
Read more >
Using files from web applications - Web APIs - MDN Web Docs
Using the File API, web content can ask the user to select local files and then read the contents of those files. This...
Read more >
File and FileReader - The Modern JavaScript Tutorial
FileReader is an object with the sole purpose of reading data from Blob (and hence File too) objects. It delivers the data using...
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