karate

Is possible to execute curl in Karate tests?


I need to run some test that use a NTLM proxy. Due to Karate doesn´t support NTLM proxy, I think that if karate can "execute" a curl command like below, I will get kate working with NTLM:

curl -X GET 'https://someaddress.com/cats?Status=completed' -u siteuser:sitepasswd    --proxy-ntlm --proxy-user ckuser:ckpasswd --proxy internal-ntlm-proxy:8080 -s 

Anyone knows if I can call a curl command in Karate? (instead of the internal http request that Karate use when call Given... Path...)

Thanks


Solution

  • Yes, Karate has very good CLI support, if curl is present on your OS, it can be done. See this answer for details, available in 0.9.6 https://stackoverflow.com/a/62911366/143475

    In your case, try first with karate.exec()

    * def result = karate.exec("curl -X GET 'https://someaddress.com/cats?Status=completed' -u siteuser:sitepasswd    --proxy-ntlm --proxy-user ckuser:ckpasswd --proxy internal-ntlm-proxy:8080 -s")
    

    And result will contain the console text. Note that there are regex helpers to make scraping values out easier, for e.g.:

    * def token = karate.extract(result, 'some(pattern).+', 1)
    

    For more tips on how to parameterize tests to be dynamic and use variables, refer: https://stackoverflow.com/a/73230200/143475