I want to reuse one payload across all my scenarios of the same feature file, using Scenario Outlines and Examples that set the payload parameters correctly. I noticed that the payload json I defined in the Background section, did not get their placeholder variables replaced.
(Java 9, Karate 0.9.0) To showcase my issue, I boiled it down to:
Feature: Some Test
Background:
* def globalVariable = {name: <name>}
Scenario Outline: Successfully register a single valid user
* def inlineVariable = {name: <name>}
* print "from global : ", globalVariable
* print "from inline : ", inlineVariable
Examples:
| name |
| 'Bob' |
Result:
16:38:00.602 [main] INFO com.intuit.karate - [print] from global : {
"name": "<name>"
}
16:38:00.608 [main] INFO com.intuit.karate - [print] from inline : {
"name": "Bob"
}
Would someone please explain to me, why the global json structure 'globalVariable' does not get the variables replaced?
Because placeholders work only within the Scenario Outline
. I think it will be really confusing to support in the Background
because you can have normal Scenario
-s in the same Feature
.
So please do the substitution within the Scenario Outline
body itself - even if it means you repeat a line or two. Not a big deal IMO.