Jess
Jess

Reputation: 41

How can gets all tags and cucumber scenarios without run tests

I would like somehow get list of all tags which I used in my project and get all names of cucumber scenarios which I have in my project without run tests. Could someone helps me how can I do this?

Upvotes: 4

Views: 4107

Answers (3)

lourdes
lourdes

Reputation: 191

Launch a bash shell and go to the folder. Type:

grep -nri "Scenario:\|Scenario Outline:" .

to get all tests. And:

grep -nri "@" .

To get all tag names

(In both cases, pay attention to the dot at the end of the command line)

Upvotes: 1

Grasshopper
Grasshopper

Reputation: 9058

As suggested by @mpkorstanje you can create a custom plugin for this.

public class DryRunPlugin implements EventListener {

    @Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(TestCaseStarted.class, this::handleCaseStarted);
    }

    private void handleCaseStarted(TestCaseStarted event) {
        System.out.println(event.getTestCase().getUri());
        System.out.println(event.getTestCase().getName());
        System.out.println(event.getTestCase().getScenarioDesignation());
        event.getTestCase().getTags().stream().forEach(t -> 
        System.out.println(t.getName()));
    }

}

@CucumberOptions(glue = "stepdef", plugin = {
        "formatter.DryRunPlugin" }, features = "src/test/resources/feature/", dryRun = true)

You will get the output as below.

file:src/test/resources/feature/scenarios1.feature
Scenario 1
src/test/resources/feature/scenarios1.feature:5 # Scenario 1
@Feature
@ScenarioOne

The sample feature file.

@Feature
Feature: Scenario and Scenario Outline Combination

  @ScenarioOne
  Scenario: Scenario 1
    And this is "FIRST" step
    And this is "SECOND" step

Upvotes: 1

As per my best knowledge, cucumber shall not allow you to get list of all tags and scenarios name without executing tests.

May be you would need to use some scripting language like VB Script, search for position of @ in file and get tag name and save one by one under a file. Similarly, after Scenario, Outline, get the whole line text and save one by one in a file and repeat same for all files under a directory.

Upvotes: 0

Related Questions