Hopefully the samples are to the point enough to show the issue, when ran.
In a @setup use, we were looking to replace a field with a dynamic value (variable). While this works in a basic scenario, usage in the @setup block fails with an error as follows. Is this expected functionality or a bug?
* replace testGenerator
| token |value! |
| replaceVar |replacementVar |
| replaceString |'replaced String' |
expression error (replace string values need to be within quotes): js failed:
>>>>
01: replacementVar
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "replacementVar" is not defined
- <js>.:program(Unnamed:1)
Here is a code sample showing the replacement of the variable working in the single scenario, but failing in the outline and @setup usage.
Feature: scenario outline using a dynamic generator function
Background:
# setting url
* url 'https://www.google.com'
* def replacementVar = 'this was a replaced variable'
* configure continueOnStepFailure = true
@setup
Scenario: setup of data
# creating json data and casting as string for replacement
* def testGenerator = [{ name: 'test replaceVar', replaceVar: '<replaceVar>'},{ name: 'test replaceString', replaceVar: '<replaceString>' }]
* print 'testGenerator-initial-',testGenerator
# printing current generated data value
* string testGenerator = testGenerator
* print 'testGenerator-string-',testGenerator
# replacing data in generated data
* replace testGenerator
| token | value! |
| replaceVar | replacementVar |
| replaceString | 'replaced String' |
# converting generated data back to json object for use in scenario
* json testGenerator = testGenerator
# printing updated generated data value
* print 'testGenerator-json-',testGenerator
Scenario Outline: Outline test name: ${name}
# printing initial name value
* print 'name-',name
# printing initial replaceVar value
* print 'replaceVar-',replaceVar
Examples:
| karate.setup().testGenerator |
Scenario: Scenario test
# creating json data and casting as string for replacement
* def testGenerator = [{ name: 'test replaceVar', replaceVar: '<replaceVar>'},{ name: 'test replaceString', replaceVar: '<replaceString>' }]
* print 'testGenerator-initial-',testGenerator
# printing current generated data value
* string testGenerator = testGenerator
* print 'testGenerator-string-',testGenerator
# replacing data in generated data
* replace testGenerator
| token | value! |
| replaceVar | replacementVar |
| replaceString | 'replaced String' |
# converting generated data back to json object for use in scenario
* json testGenerator = testGenerator
# printing updated generated data value
* print 'testGenerator-json-',testGenerator