2

I'm trying to create the path for the Odata URL in Karate. The path looks like: '/opu/odata/srt/ZQ_SRV/ZQ_BI_Q001(OPT_1='0013076036',OPT_To='0013076036')/Results'

It seems like Karate can't read special characters like round brackets () and ' '. And it cuts the url after opu/odata/srt/ZQ_SRV/ZQ_BI_Q001 right before the round brackets starts. And the rest of the url (OPT_1='0013076036',OPT_To='0013076036')/Results looks like a text.

I've tried to use %28 for ( and 29% for ) and %27 for ' but it didn't help.

P.S.When running the same url in Postman the call went successfully

Running the test url:

Background:
    * url "https://httpbin.org/anything/opu/odata/srt/ZQ_SRV/ZQ_BI_Q001(OPT_1='0013076036',OPT_To='0013076036')/Results"
  Scenario: test check
    * method get

enter image description here

Y_Sh
  • 121
  • 2
  • 4
  • 14

2 Answers2

1

Try building the url fully by hand and don't use param or path:

* url "http://myhost/opu/odata/srt/ZQ_SRV/ZQ_BI_Q001(OPT_1='0013076036',OPT_To='0013076036')/Results"

If that still doesn't work, it is likely your server does not handle encoded URL-s correctly which could be a bug: https://stackoverflow.com/a/54477346/143475

EDIT: just try these 2 lines to prove there is nothing wrong with Karate / or see this simpler example: https://stackoverflow.com/a/67068873/143475

* url "https://httpbin.org/anything/opu/odata/srt/ZQ_SRV/ZQ_BI_Q001(OPT_1='0013076036',OPT_To='0013076036')/Results"
* method get

This is the result:

Running com.intuit.karate.junit4.dev.TestRunner
23:11:06.404 [main] DEBUG com.intuit.karate - request:
1 > GET https://httpbin.org/anything/opu/odata/srt/ZQ_SRV/ZQ_BI_Q001(OPT_1='0013076036',OPT_To='0013076036')/Results
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: httpbin.org
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_231)

23:11:08.154 [main] DEBUG com.intuit.karate - response time in milliseconds: 1745.46
1 < 200
1 < Access-Control-Allow-Credentials: true
1 < Access-Control-Allow-Origin: *
1 < Connection: keep-alive
1 < Content-Type: application/json
1 < Date: Wed, 22 Jan 2020 17:41:07 GMT
1 < Referrer-Policy: no-referrer-when-downgrade
1 < Server: nginx
1 < X-Content-Type-Options: nosniff
1 < X-Frame-Options: DENY
1 < X-XSS-Protection: 1; mode=block
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept-Encoding": "gzip,deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Apache-HttpClient/4.5.5 (Java/1.8.0_231)"
  }, 
  "json": null, 
  "method": "GET", 
  "origin": "49.206.14.183, 49.206.14.183", 
  "url": "https://httpbin.org/anything/opu/odata/srt/ZQ_SRV/ZQ_BI_Q001(OPT_1='0013076036',OPT_To='0013076036')/Results"
}
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • No, it didn't help, the url breaks before (. Weird, because same url call went successfully in Postman. It seems like Karate can't read the url properly. Any ideas? – Y_Sh Jan 22 '20 at 17:33
  • @Y_Sh then use Postman :P - but seriously, see my edit to the answer – Peter Thomas Jan 22 '20 at 17:42
  • Hey @Peter Thomas, I've run your test, it turned green but the URL looks unglued in the console . Added the screenshot with your test into the description – Y_Sh Jan 22 '20 at 18:04
  • You're using * method get. My code looks like When method get Then status 200. When calling your test url with my code, it's throwing the error. – Y_Sh Jan 22 '20 at 18:11
  • @Y_Sh I have nothing to add. the "unglued" is normal, your IDE doesn't detect the URL probably (because it is a badly designed API IMO) - follow these instructions if needed: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jan 22 '20 at 18:15
  • Gotcha. Looks if I use "* method get" instead "When method get Then status 200." my link went through. Is " * method get " it the alternative method of calling the url? – Y_Sh Jan 22 '20 at 18:21
  • @Y_Sh please refer to the syntax doc: https://github.com/intuit/karate#method – Peter Thomas Jan 22 '20 at 18:23
-1

Resolved issue by putting * method get instead of When method GET Then status 200

Y_Sh
  • 121
  • 2
  • 4
  • 14
  • I can confirm that this is *not* the correct answer :) there is no difference between `When method GET` and `* method get` – Peter Thomas Jan 22 '20 at 18:30
  • I don't know but * method get did resolved the issue, that's why I've published the answer – Y_Sh Jan 22 '20 at 19:40
  • I happen to have created Karate, so I have to make sure that your answer does not mislead and waste the time of others. without seeing all your code, we can't say what fixed the problem. which is why I asked to follow the process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jan 23 '20 at 03:19