0

I am trying to pass a dictionary from a feature file to my test file. I searched a lot but couldnt find a way to pass a dictionary.

Below is one example that is available in behave which I wanted to achieve in pytest-bdd Pass dictionaty from feature file to test

Reference link: How can I pass an object like a list or dictionary in python behave .feature file

Please let me know if someone already have a solution for the same.

Thank you.

S_G
  • 67
  • 6

1 Answers1

2

After giving many tries, now I am able to do this. Below is the script which I tried. Feature file:

  Scenario Outline: Dictionary
    Given Access Dictionary list
      [
        { "abc":"test1","def":"test2"},{ "ghi":"test3","jkl":"test4"}

      ]

Test file:

@given(parsers.parse('Access Dictionary list\n{table_data:json}', extra_types=dict(json=json.loads)), target_fixture="mytabledata")
def step_setup(table_data):
    global data
    MyTableData = UserList(table_data)
    #print(MyTableData)
    print(MyTableData[1]["ghi"])

Output: test3

HAPPY THAT I AM ABLE TO DO IT ON MY OWN :)

S_G
  • 67
  • 6