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.

Aankhen
  • 2,198
  • 11
  • 19

2 Answers2

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 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' – Automation_Test Feb 25 '19 at 14:34
  • still getting below error: com.intuit.karate.exception.KarateException: status code was: 404, expected: 200, response time: 13, url: https://www.mars.com/mars/profile/268%0A/line, response: 404 Not Found

    Not Found

    The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

    at com.intuit.karate.StepDefs.status(StepDefs.java:491)
    – Automation_Test Feb 25 '19 at 14:39
  • @Automation_Test it is time to refer you to these instructions ! all the best ;) https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Feb 25 '19 at 15:38
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.

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20