Home > front end >  Download file with Karate
Download file with Karate

Time:11-25

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:

  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?

CodePudding user response:

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.

  • Related