1

I want to create a csv file and after it send it in the request. But, when I'm trying to do this, I'm getting an error: class java.io.File cannot be cast to class java.lang.String (java.io.File and java.lang.String are in module java.base of loader 'bootstrap')

I'm creating file in the next way: Via JS functions generating content of the file, and after it, I'm using karate.write:

* def csvFile = karate.write(csvContent,fileName)

But, when I'm trying to send this, it's an error appears:

And multipart file files = { read: '#(csvFile)', filename: 'bulkUpload.csv', contentType: 'multipart/form-data'}
When method POST
Then status 200

class java.io.File cannot be cast to class java.lang.String (java.io.File and java.lang.String are in module java.base of loader 'bootstrap') What I'm doing wrong?

UPD: Also, I was trying to access created file directly, but it also doesn't work, even with absolute path

1 Answers1

1

As mentioned in the docs, you get back a java.io.File instance: https://github.com/karatelabs/karate#karate-write

So do this:

* def csvFile = karate.write('foo', 'temp.txt')
* def csvPath = 'file:' + csvFile.getPath()
* multipart file files = { read: '#(csvPath)', filename: 'bulkUpload.csv', contentType: 'multipart/form-data' }

Note the use of .txt because of this: https://stackoverflow.com/a/55643097/143475

That said, I please read this before proceeding down this path: https://stackoverflow.com/a/54593057/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248