简体   繁体   中英

karate: Dynamic Scenario Outline not working when json is defined in background

Feature: Dynamic Scenario Outline
 Background: 
  * def kittens = [{"name":"abc"},{"name":"def"}]
 Scenario Outline: cat name: <name> 
  * print <name> 
 Examples: 
  | kittens |

error after executing this code is:

 org.graalvm.polyglot.PolyglotException: ReferenceError: "kittens" is not defined

Whereas, if I put this JSON directly into examples, this is working and executing 2 time. passing as shown below:

Examples: 
  | [{"name":"abc"},{"name":"def"}] |

why am i getting "kittens" is not defined, any idea?

The Background does not work like this in new versions of Karate.

Please read: https://github.com/karatelabs/karate/releases/tag/v1.3.0

So try:

Feature:

@setup
Scenario:
* def kittens = [{"name":"abc"},{"name":"def"}]  

 Scenario Outline: cat name: <name> 
  * print name 
 Examples: 
  | karate.setup().kittens |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM