Is it possible to share data between scenario and features in Cucumber

14,458

There is no cucumber feature for that. There is helper Background cucumber background, that will execute some steps before each scenario in the feature. You can have a look into that.

Seems related How to share state between scenarios using cucumber

Seems related as well: how-to-pass-variable-values-between-cucumber-jvm-scenarios

Share:
14,458

Related videos on Youtube

alex
Author by

alex

Updated on June 04, 2022

Comments

  • alex
    alex almost 2 years

    I have separate class with static variable (e.g. List“<”Company“>”) that i need to share between tests (e.g. get, add or remove companies from list). But when a new scenario starts the data is re-initialized. Notes: the class is in separate folder, it doesn't has Cucumber hooks, and its object isn't created anywhere in cucumber classes.

    Maybe there is some analog of ScenarioContext like in SpecFlow?

    PS: i know that sharing data from test to the other is a bad approach, but in my specific case it doesn't corrupt test independency

    • Grasshopper
      Grasshopper over 7 years
      How are you instantiating the static List? Just do it the first time with a static flag and set flag to false so the List data will be persisted. Can you add the current instantiation code?
    • user861594
      user861594 over 7 years
      you can check with QAF-gherkin. It has different data and configuration management features, you can hold company list in xml as well and use it anywhere.