3

I want to create a dynamic url using karate framework. lets assume URL I want to create is :

https://www.mars.com/mars/profile/{profileID}/line

In above URL {profileID} is path.

Currently I have written below feature file which is able to create the url however due using path keyword it encodes the url and add %0A after profile id.

https://www.mars.com/mars/profile/264%0A/line

Feature File:

@smoke
Scenario: Create  a line score in existing  profile
And def urlname = marsuri+ '/mars/profile/'

Given url urlname
Given path id + '/line'

Please let me know how can I create a URL with path in between URL without encoding it.

2 Answers 2

2

You are not using the path syntax correctly. Please read the documentation: https://github.com/intuit/karate#path

Make this change:

Given path id, 'line'

EDIT: please also see this answer: https://stackoverflow.com/a/54477346/143475

Sign up to request clarification or add additional context in comments.

3 Comments

I used as suggested however , @smoke Scenario: Create a line score in existing profile And def urlname = marsuri+ '/mars/profile/' Given url urlname Given path id, 'line'
still getting below error: com.intuit.karate.exception.KarateException: status code was: 404, expected: 200, response time: 13, url: mars.com/mars/profile/268%0A/line, response: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>404 Not Found</title> <h1>Not Found</h1> <p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p> at com.intuit.karate.StepDefs.status(StepDefs.java:491)
@Automation_Test it is time to refer you to these instructions ! all the best ;) github.com/intuit/karate/wiki/How-to-Submit-an-Issue
0

Actually that id variable wherever you are getting it from is having a new line at the end of the string, something like this "264\n" that is why it is getting encoded to 264%0A

If all you wanted to pass is "264" you have to remove the unwanted values before adding it to the path

Background:
* def removeNewLine = function(x){return x.replace("\n","")}

Scenario: Create  a line score in existing  profile
And def urlname = marsuri+ '/mars/profile/'
Given url urlname
* def id = removeNewLine(id)
Given path id + '/line'

If you can modify the data directly from the source where you are getting the id that would be great.

1 Comment

Great Babu Sekaran, It worked , I never realized id was carrying "\n" with it. Good Catch

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.