serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

can't read tags from within test, nor exlclude scenarios with tags #95

Closed asvdw closed 6 years ago

asvdw commented 7 years ago

Hello, using Serenity-core 1.5.9, serenity-junit (1.5.9), serenity-cucumber (1.5.7) and maven plugin (1.5.9), I can't read tags within tests. According to the documentation (http://thucydides.info/docs/serenity-staging/#_running_scenarios_by_tags), this should do the trick:

Map<String, String> metadata = Serenity.getCurrentSession().getMetaData();

But the map is still empty. In fact metadata and tags are not the same concept, so is it possible to access tags ?

Futhermore, tags like @Pending and @Ignore (ih feature files or step definitions) does't skip tests (as expected, see http://thucydides.info/docs/serenity-staging/#_skipping_tests). Tests are run, then marked as skipped in report. No way to really skip them, or adjust test execution through tags ?

Thank you for your help.

This is my feature file:

asvdw commented 7 years ago

update: I can exclude execution of test with tags using @CucumberOptions(tags={"~@DoNotRun"}) but I still would like to read tags to adjust execution.

Thank you.

wakaleo commented 7 years ago

MetaData is a JBehave concept; it looks like it hasn't been implemented in the Cucumber implementation, so that is a bug/missing feature/inconsistency in the API. (That would be an easy PR if you are interested).

Tests marked with Pending or Ignore are, strictly speaking, executed in "dry-run" mode, so that the reports include them correctly. This is normal behaviour, as otherwise Serenity could not do its "living documentation" reporting. And yes, tf you want to skip them completely (so they don't appear in the reports at all), use the Cucumber tag options.

asvdw commented 7 years ago

Indeed the use of "native" cucumber classes is simple, I now use this hooks, which is not perfect but is usable:

    @Before
    public void addTags(Scenario scenario) {
        scenario.getSourceTagNames().stream()
                .map(t -> t.replaceFirst("@", ""))
                .forEach(tagname -> {
                    String[] parts = tagname.split(":");
                    String key = parts[0];
                    String value = parts.length > 1 ? parts[1] : "";
                    Serenity.getCurrentSession().addMetaData(key, value);
                });
    }

Note that Tags with form "@ value" (and not @ key:value) are set as keys in metadata map...

Thank you for your replay and this great tool ;)

RulerOf commented 6 years ago

In case anyone googles their way in here, I was trying to discover the tags available on my test suite as part of some back-end automation work. I don't know much of anything about Java or the whole ecosystem around Serenity's testing process, so I don't have any context for what steps are required to even run the code above.

I was able to get a verbose cucumber output of the test specifications(?) by running cucumber -v src/test/resources/ from the root of my serenity code repo. From that point, I was able to process that output with some shell code to get my tag list. It's ugly and fragile, but functional.

for tag in $(cucumber -v src/test/resources | grep '^[[:space:]]*@' | while read tag; do echo $tag; done); do echo $tag; done | sort -u

This may or may not work for anyone else. I'm not sure how specific this is to my developers' coding style or not. Just sharing in the hope that it's useful to someone else.