1

I have read the documentation on: https://github.com/intuit/karate#path

I have also read many answers on related subject on these forums, most notably: How to dynamically create URL having path in between URL using Karate framework

However, I still cannot get my head around this concept. Perhaps I am even more a newbie than a typical newbie. My problem is this:

The complete api: /sample/api/v1/sampleweb/{sampleweb}/webversion/{version}

    Feature:
    
        Background:
            * def baseUrl = '/sample/api/v1/'
    
        @postRandomData
        Scenario: POST API for creating data
            Given url host
            And path baseUrl

How in the world can I add the rest of the Url to "baseUrl" (basically the complete path listed above)? Should I throw "sampleweb/{sampleweb}/webversion/{version}" into a variable and then just do "baseUrl + variable"?

Please advise.

hungryhippos
  • 617
  • 4
  • 15

2 Answers2

2

@hungryhippos what i do to have this kind of flexibility is to use something like:

var endpoint =  '/sampleweb/{sampleweb}/webversion/{version}'
.replace('{sampleweb}', param1)
.replace({version}', param2)
aleruz
  • 133
  • 5
1

Just use string concatenation. Just like normal JavaScript. Here try to spot the difference between "hard coded" strings and variables.

* def want = 'something'
* url baseUrl + '/anything'
* path 'you', want
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • If I understand correctly, I can possibly do something like: `And path baseurl + '/sampleweb/{sampleweb}/webversion/{version}'` – hungryhippos Apr 16 '21 at 15:15
  • @hungryhippos no you can't – Peter Thomas Apr 16 '21 at 15:31
  • I think I will do: `And path baseurl, 'sampleweb', sampleweb, 'webversion', version` And remove the "/" from the baseUrl variable so there is no extra forward slash. – hungryhippos Apr 16 '21 at 16:07
  • @hungryhippos I think you still haven't got it. you can't mix a URL (which starts with `http`) and the `path` keyword. anyway, just try a few combinations (or read the docs ;) – Peter Thomas Apr 16 '21 at 16:09
  • 1
    It's an API call, I misworded my request perhaps. It's not a traditional URL (starting with http). But yes, I will try combos as you suggested. Thank you so much for your assistance! – hungryhippos Apr 16 '21 at 16:20
  • 2
    @hungryhippos what i do to have this kind of flexibility is to use smth like: var endpoint = '/sampleweb/{sampleweb}/webversion/{version}'.replace('{sampleweb}', param1).replace({version}', param2) – aleruz Apr 22 '21 at 18:58