Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Download file with Karate

I want to download a (100MB debian) file from a network location. I don’t want to interact with the file; I just want it saved on my system. As input, I have the url and api key (passed as header). The following curl command works in my terminal:

curl --insecure -H key:value --output C:\Users\username\filename.deb https://path/filename.deb

So I tried curl like this:

  Scenario: Download file
    * karate.exec('curl --insecure -H key:value --output C:\Users\username\filename.deb https://path/filename.deb')

But nothing happens. Then I tried writing the response, left out the output field, but the result is 190MB instead of 100MB:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  Scenario: Download file
        * def result = karate.exec('curl --insecure -H key:value https://path/filename.deb')
        * karate.write(result, 'fw.deb')

Is there a way to just execute a command (I tried karate.fork and it didn’t do anything either) and not need to catch the result and write it to a file?

>Solution :

If you are not able to get karate.exec() or karate.fork() to work, then the only option I suggest is to write some Java code to do this specific thing, and that way you can involve this weird step into your test-script.

For details on how to use karate.exec() refer: https://stackoverflow.com/a/62911366/143475

It is tricky to get the Java process to correctly locate executables on the file-system. You can experiment if setting the env property with things like the system PATH make a difference. Or using the full, absolute path to curl wherever it is installed etc.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading