Karate: how to pass dynamic path parameters? - cucumber-jvm

Suppose I have test scenario with exact same requirements but one path variable change as follows:
Scenario: Some scenario
Given path /mypath/param1
When method get
Then status 200
I need to run the same test for /mypath/param2, /mypath/param3 as well.
Is there a simpler way to do it without requiring to separate the feature into a separate file and using data driven test?

Yes, use the Scenario Outline which is a standard Cucumber pattern.
Scenario Outline: Some scenario
Given path /mypath/<param>
When method get
Then status 200
Examples:
| param |
| foo |
| bar |

Related

How to render Karate.Config values in Scenario outline

I am just wondering if there is a way to make use of karate.config values in Scenario Outline statement. Please have a look at the example below:
Feature: Sample feature
Scenario Outline: Sample scenario for id: <id>
Examples:
| id |
| partnerId |
Here the partnerId is defined in Karate.config file (just say it is '123'). When I run the file I want to see '123' in scenario outline in reports rather than the value holder 'partnerId'
Expected:
You are asking for variables to be able to be substituted into the title. Sorry, that's not supported. You can always print these values so they will show in the HTML report, but yes - not as the title.

Karate: Run a Scenario file on two different url's

I have a requirement in my project to run a Scenario file on two different urls. All the request headers for both the URL's are exactly the same.
Planning to use similar to below
Scenario Outline: Test
Given url <testurls>
And path 'test'
When method GET
Examples:
|testurls |
|'https://test1.com' |
|'https://test2.com' |
Is there any other better way to handle it in Karate ?
This should be the simplest way.

Can I use the same below feature for the Json Api request aswell

Xmlsample.feature
Feature: test A
Scenario: test apple
* table test_apple_one
| payload_file |
| 'sample/ball.xml' |
* def result = call read('classpath:........./samplereq.feature') test_apple_one
Jsonsample.feature
Feature: test B
Scenario: test Mango
* table test_Mango_one
| payload_file |
| 'sample/cat.`enter code here`json' |
samplereq.feature
Feature: sample
  Background:
#Common Config load  
* def sampleURL = baseURL+'/sample/test'      
* xml payload = read('classpath:.....'+payload_file)   
#OAuth Signature generator
* def authorization = "oauth string"
  Scenario: Make the sample API call
Given url sampleURL`enter code here`
Given header Authorization = authorization
Given request payload
And header Content-Type = 'application/xml;charset=UTF-8'
And header Host = host
And header Accept = content_type
When method post    
Then match header Content-Type contains 'application/xml'
I am using the above feature samplereq.feature for the XML API request and
I Want to keep this feature samplereq.feature as generic and use the same for the Json Api request.can I do the same with JSON(Jsonsample.feature) API request ,please suggest
I read your question multiple times and I am sorry I can't understand what you are trying to do at all. Also I think you have not understood Karate properly. So please listen to my suggestion and take it in the right spirit.
I think you are trying to un-necessarily complicate your test. My sincere suggestion is - please don't try for this extreme re-use. I have observed that when teams attempt to create a super-generic re-usable test script - it just complicates things and becomes hard to maintain.
So please use different feature files for JSON and XML. For each test you can have multiple scenarios. Now, the scenario data can be the same for JSON and XML and you can read a common JSON file. Refer to this example on how you can create XML out of JSON: https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/xml/xml.feature
If you still insist on the JSON and XML both in a generic feature, please take a look at this example: https://github.com/intuit/karate/tree/master/karate-demo/src/test/java/demo/loopcall
The above also has an example of calling a JavaScript function. Also please read the docs carefully.

Use of Scenario outline in passing the scenario name as example

Can I use scenario outline concept in scenario name in Specflow so that I pass the scenario name in Example. For example if I want to run my scenario in three browsers IE, FF and chrome, I'll pass three examples.
I have tried it in Cucumber and it works, can I do it with Specflow in VS ?
Like
Scenario outline : <Scenario name>
steps 1
step 2
Examples:
|Scenario name|
|scenario 1 |
|scenario 2 |
|scenario 3 |
can I implement that ?

How to overwrite some data's in columnFicture?

my ColumnFicture test table look like this:
|categoryId|subcategoryId|showResults?|
| 2 | 1 | |
I overwrite in my ficture code (C#) categoryId (2) if subcategory is more than 0. Is that possible overwrite categoryId on fitnesse test site? That evry one can see what happend.
No, from your fixture code you can not change the test in the FitNesse wiki. A test in the wiki is rendered into HTML, passed to a FitServer, parsed into a tree structure, passed to your fixture which can modify the tree, and then rendered into the test result HTML. So your fixture is too far down the pipeline to access the original wiki test source.