Reading file and embedd file content in JS leads to
See original GitHub issueThis 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:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@peterquiel I made a commit that hopefully puts this discussion to rest, will close the PR
@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" }
this results in:
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