Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CucumberOptions: Tags and name do not work well together #976

Closed
tcwmj opened this issue Mar 26, 2016 · 10 comments
Closed

CucumberOptions: Tags and name do not work well together #976

tcwmj opened this issue Mar 26, 2016 · 10 comments
Labels
⚡ enhancement Request for new functionality

Comments

@tcwmj
Copy link

tcwmj commented Mar 26, 2016

If I only set tags in cucumberOptions, it can filter which scenarios match the tags will be executed.
If I only set name in cucumberOptions, it also can filter which scenarios match the name will be executed.
if I only set feature path and scenario lines, it also can filter which scenario match the line will be executed

if I both set tags and name (or scenario line), nothing will be executed with output "Test Ignored", I expected it can filter by both tags and scenario name.

Here is my cucumber options.

@CucumberOptions(strict = true,
    features = {"classpath:features/F00001.feature"},
    format = {"json:cuccumber.json", "pretty"},
    monochrome = true,
    tags = {"~@manual", "~@deprecated", "~@todo", "~@wip", "~@ignore"},
    glue = { "org.some.steps" },
    name = {"^Verify what I expected$"})
@tcwmj
Copy link
Author

tcwmj commented Mar 26, 2016

I found in method detectFilter in FilterFormater.java, IllegalArgumentException will be thrown when filterClasses >1, does only single type be expected? tags, or lines, either names,

   private Filter detectFilter(List filters) {
        Set<Class> filterClasses = new HashSet<Class>();
        for (Object filter : filters) {
            filterClasses.add(filter.getClass());
        }
        if (filterClasses.size() > 1) {
            throw new IllegalArgumentException("Inconsistent filters: " + filters + ". Only one type [line,name,tag] can be used at once.");
        }

        Class<?> typeOfFilter = filters.get(0).getClass();
        if (String.class.isAssignableFrom(typeOfFilter)) {
            return new TagFilter(filters);
        } else if (Number.class.isAssignableFrom(typeOfFilter)) {
            return new LineFilter(filters);
        } else if (Pattern.class.isAssignableFrom(typeOfFilter)) {
            return new PatternFilter(filters);
        } else {
            throw new RuntimeException("Could not create filter method for unknown filter of type: " + typeOfFilter);
        }
    }

@brasmusson
Copy link
Contributor

Specifying tags, specifying (scenario) name, and specifying feature path and line are three different way of specifying which scenarios to execute. You can only use one of them at the time.

@tcwmj
Copy link
Author

tcwmj commented Mar 26, 2016

Thanks @brasmusson, I expect to add these kinds of filter to work together as it's a real requirement.
BTW, is that possible to change default FilterFormatter to custom one? how to configure by CLI or cucumber options?
eg. --plugin "filter:org.something.CustomFilterFormatter"

@brasmusson
Copy link
Contributor

Then you would also have to design a way to specify how they should be combined. "Run all scenarios that matches this tag expression plus the scenarios that matches this name expression" is very different from "Run all scenarios that matches this tag expression if they also matches this name expression".

It is not possible to change the FilterFormatter to a custom one.

@tcwmj
Copy link
Author

tcwmj commented Mar 26, 2016

Thanks, I expect "tags and names", but someone might prefer "tags or names", so the default FilterFormatter keeps a single filter....

@aslakhellesoy aslakhellesoy added Core ⚡ enhancement Request for new functionality 🙏 help wanted Help wanted - not prioritized by core team labels Aug 30, 2016
@aslakhellesoy
Copy link
Contributor

This sounds like an unusual requirement, but I don't see the harm in adding it. If you can send us a pull request we'll consider it.

@brasmusson brasmusson removed the 🙏 help wanted Help wanted - not prioritized by core team label Sep 1, 2016
@brasmusson
Copy link
Contributor

With #1035 (the upgrade to use Gherkin4), this will be changed (there the FilterFormatter which is a Gherkin2 thing, will not exist). Currently the approach is to use a filter chain similar to in Cucumber-Ruby, so for a pickle to be executed it need to be accepted by the line filters (if any), the tag filters (if any), and the name filters (if any). That is both name and tags can be used at the same time - with an and semantic.

@tcwmj
Copy link
Author

tcwmj commented Sep 2, 2016

Sounds great! I think we can close this issue if Gherkin4 has this feature.

@brasmusson
Copy link
Contributor

Now when #1035 has been merged, the 2.0.0-SNAPSHOT version from the master branch (with the groupId io.cucumber), support tags, names and lines (lines on the feature paths) at the same time - with an and semantic.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

3 participants