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.

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Very interesting solution. Thank you for sharing.
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

6 Comments

If I understand correctly, I can possibly do something like: And path baseurl + '/sampleweb/{sampleweb}/webversion/{version}'
@hungryhippos no you can't
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.
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 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)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.