How to render Karate.Config values in Scenario outline - karate

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.

Related

How to differentiate test description for parameterized data testing with selenium/cucumber?

How to differentiate test description for parameterized data testing with cucumber? Because for multiple testdata, the description in the scenario outline is showing same when viewing the cucumber report.
Below I am giving an example. On cucumber result, the scenario outline "Verify correct status displaying after filtering" -always visible as same for all the testdata. Is it possible to show three different description for three different testdata? Like "Verify correct verified status displaying after filtering" / "Verify correct pending status displaying after filtering" / "Verify correct rejected status displaying after filtering".
#flights
#flight01
Scenario Outline: TC003_Verify correct status displaying after filtering
Given I am in the xyz application
When I navigate to abcd page
Then Select status "<Status>" from the filter
Then Verify correct "<Status>" should be displayed
Examples:
|Status |
|Verified|
|Pending |
|Rejected|
The way to do that would be to add the parameter to your scenario outline the same way you do for your steps:
eg.
TC003_Verify "<Status>" status displaying after filtering for "<Status>"
This way your scenario results will better convey what you are testing too.
HTH.
The easy way is to just write 3 different scenarios with different titles. There is absolutely no need to use scenario outline when cuking.
When I tested for multiple test data,cucumber report shows the data itself and marked it with pass or fail colors, screenshots below . The description in scenario outline is same but it also copies all the data and it even provides the error. Imo, this eliminates the need to have separate scenario outline with data in it.
and
You have not mention which test runner are you using but the above screen shots are from cucumber 6.9.1 and Junit5 and in junit-platform.properties , you can mention cucumber.plugin = html:target/cucumber.html to have this report generated

Karate : can dynamic-csv.feature work for Get Request, how to pass dynamic path parameters from CSV? [duplicate]

This question already has an answer here:
How do I invoke my JS Function for a particular column in a csv file in the Karate Framework?
(1 answer)
Closed 1 year ago.
Trying to pass dynamic path parameters from CSV for a GET method.
Referring to Karate: how to pass dynamic path parameters?
we are trying to pass dynamic parameter in path from a CSV file, but it doesn't work well when method is GET, although for POST we don't have an issue using CSV.
here elaborating with help of a open API
Feature: Get users details based on valid and invalid inputs from csv file
Background:
* url 'https://reqres.in'
Scenario Outline: Get single user based on id value - Valid & invalid
Given path '/api/users/<id>'
When method <method>
Then status <status>
* print response
##* match response.data.id contains <id>
Examples:
|id|status|method|Scenario|
|2|200|GET|Valid id as input|
|4|200|GET|Valid id as input|
|5|200|GET|Valid id as input|
|&|404|GET|Special character as Input|
| |404|GET|Empty space as Input|
|A|404|GET|Alphabet as input|
|999|404|GET|Invalid Number as input|
|-1|404|GET|Invalid Number as input|
This works well, but when I try to pass same data with following it doesn't work
|read('../../Data/users.csv')|
this is how this CSV looks
users data csv file
It is hard to say from the data given, and it doesn't work is not helpful. Maybe special characters cause problems. The best thing would be to follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
In general I discourage using a Scenario Outline for negative cases. Some guidance can be found here: https://stackoverflow.com/a/54126724/143475
To troubleshoot the CSV, you can try * print __row to see the values in each row.
This works for me:
Scenario Outline:
* url 'https://httpbin.org'
* path 'post'
* request __row
* method post
Examples:
| read('test.csv') |

Karate: how to pass dynamic path parameters?

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 |

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.

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.