1

I am using the path keyword from Karate API framework to make a request. The path is a stored in a variable that is returned from another feature file. However, I am not able to pass '?'. Here is what I am doing:

I have a 'paths.feature' file that gets all the paths for my subsequent requests. Below is an example of a path returned:

/LegalEntity/{legalEntityId}/taxidentifier/{Id}?formId=captureCustomerContact&subformid=taxIdentifierSimplified

I then "replace" the params like below:

/LegalEntity/43/taxidentifier/13?formId=captureCustomerContact&subformid=taxIdentifierSimplified

I then call this feature file from a new feature file and pass the stored variable (def) into the path, however, the URL does not ignore the '?' and the test fails. Any pointers or help would be appreciated. Thanks

ERROR

/LegalEntity/43/taxidentifier/13%3FformId=captureCustomerContact&subformid=taxIdentifierSimplified

Mark Hughes
  • 73
  • 1
  • 5
  • Hi Peter. I understand how to pass data from one feature file to another. The issue here is that when I call the 'def' from the other feature and pass it in as the 'path' it does not accept the '?'. How can I pass this as the path? **/LegalEntity/43/taxidentifier/13?formId=captureCustomerContact&subformid=taxIdentifierSimplified** – Mark Hughes Oct 26 '21 at 11:45

1 Answers1

0

I think you are confused, and this has nothing to do with calling a feature.

When you have special characters in a path, it will be encoded. That's how HTTP works. Refer: https://stackoverflow.com/a/54477346/143475

Try the following 3 line test and see what happens:

* url 'https://httpbin.org'
* path 'anything/?'
* method get

The URL actually sent will be: https://httpbin.org/anything/%3F

But you need to understand that the ? will automatically be inserted when you use the param keyword correctly:

* url 'https://httpbin.org'
* path 'anything'
* param foo = 'bar'
* method get

And here the URL will be: https://httpbin.org/anything?foo=bar

So what you should be doing is re-factoring your test to pass formId and subformid as query params, for example:

* def someVariable = 'captureCustomerContact'
* url 'https://httpbin.org'
* path 'anything'
* param formId = someVariable
* method get

Please take some time to study how this works. Here the URL will be https://httpbin.org/anything?formId=captureCustomerContact and of course, you can have more param instances. Read the docs please: https://github.com/karatelabs/karate#param

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