0

I'm looking for a way in lettuce to specify code to run from my Gherkin feature file such that it has already run when I get to the @before.each_scenario hook - this is essentially to do a dynamic set of examples for a scenario outline, so given an application which has a catalogue of things, each of which I want to test, I want to be able to do something like the following:

Feature: Automated Catalogue Test
    In order to have use the system
    As a user
    I want to be able to use each feature in the catalogue

    Background:
      Given I start the system
        And I have a list of features

    @foreach
    Scenario Outline: I use each feature in the system
      Given feature <feature_num>
       When I load the feature
        And I use the feature in the way they are all used
       Then I can clear up the feature

So I have this working for a pre-set list of examples, and I have been able to test the logic just by using a hook to extend the scenario, and it works, however this means that if one feature fails those that would be after will not run.

If the Background step were to run only once and before the @before.each_scenario then I could set the list of outlines that are enumerated at lettuce/core.py:722, however as far as I am aware this is not part of the Gherkin language; I would not want to add I have a list of features to the terrain though as there are many other tests that don't need to know about this catalogue...

I don't suppose anyone has any suggestions?

codeape
  • 97,830
  • 24
  • 159
  • 188
theheadofabroom
  • 20,639
  • 5
  • 33
  • 65

1 Answers1

0

Currently as a compromise I have come up with this:

Feature: Automated Catalogue Test
    In order to have use the system
    As a user
    I want to be able to use each feature in the catalogue

    @foreach @foreach_feature
    Scenario Outline: I use each feature in the system
      Given feature <feature_num>
       When I load the feature
        And I use the feature in the way they are all used
       Then I can clear up the feature

Then where I implemented the hook which looks for the @foreach tag I added a lookup to a tag registry where I have stored a callback to run if you find the @foreach_feature tag. This still doesn't seem ideal, but I'm putting it out there for anyone trying to solve the same problem, until a better solution is found.

theheadofabroom
  • 20,639
  • 5
  • 33
  • 65