I need to run all scenarios in a feature file against multiple urls (endpoints) one endpoint at a time. Basically I have a list of servers that's injected into the karate config object as an array. I call them in several feature files where I trigger all the scenarios against one URL (string) from the server list (array) at a time.
For instance, we have 1 feature file with 2 scenarios and a server list with 5 endpoint URLs. (FYI - we will be triggering several feature files in reality)
We set the url
to first endpoint from the server list (array) and trigger the 2 scenarios with that URL only. Then repeat for the next 4 endpoints. Are we making 2 HTTP request per endpoint since we have 2 scenarios or 1 HTTP request per endpoint?
I referenced the Dynamic Scenario Outline example from the Karate docs. The JSON array data source example actually triggered all the scenarios with each URL one by one. However, I need to use the Examples table for another set of data for each scenario. This capability is triggered when the table consists of a single "cell", i.e. there is exactly one row and one column in the table.
I tried using @setup
but I need to upgrade my Karate to 1.x and above ((I'm using 0.9.3) to find out if that would work. However, I have been running in circles with this. Is there an easier way to resolve this? Am I on the right track? Will using @setup
be a good option to achieve what I described? Or should I look into using Background
?
Context:
serverList
defined in karate.config.js
--> ['www.cat.com', 'www.dog.com', 'www.horse.com']
// an array with string elements (urls)
Feature: Run all the scenarios against each endpoint url
@setup
Scenario: Trigger all the scenarios with ONE endpoint url at a time
* def endpointObj = karate.mapWithKey(serverList, 'endpointUrl')
Scenario Outline: Print endpoint
* def baseUrl = '<endpointUrl>'
Examples:
| karate.setup().endpointObj |
Scenario: First scenario
* url baseUrl // I feel like i'm messing up here. Will this work?
* print baseUrl // 1. 'www.cat.com', 2. 'www.dog.com' 3. 'www.horse.com' 4..5
Scenario: Second scenario
* url baseUrl // I feel like i'm messing up here. Will this work?
* print baseUrl // 1. 'www.cat.com', 2. 'www.dog.com' 3. 'www.horse.com' 4..5
Expected Outcome: trigger all scenarios against each endpoint URL from the server list.
If there are 2 scenarios and 5 endpoints in 1 feature file, there will be a total of 10 tests.