1

Feature: API Testing feature

  Background:
    * configure logPrettyRequest = true
    * configure logPrettyResponse = true
    * def data = call read('classpath:Features/GetData.feature')
    * print data // prints the data as expected.

  @setup
  Scenario: get Data from 
   
    * print "data ==>  ",data

    Getting Below error when printing data variable in setup scenario.

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

is this feature supported by karate?

Shreyansh Jain
  • 498
  • 4
  • 7

1 Answers1

1

The @setup cannot use the Background, it is designed to create data "from scratch" and nothing else. You can still use variables from the global config of course. Think of the @setup as only a way to create data for a dynamic Scenario Outline. Then each row uses a Background like normal.

If you are concerned about "re use", my advice is don't be.

If you really want - you can create a re-usable feature, and use it from both the Background and @setup but I really wouldn't recommend that. Try to design your tests to be simpler and better would be my advice.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248