How can gets all tags and cucumber scenarios without run tests

与世无争的帅哥 提交于 2020-12-31 04:32:14

问题


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?


回答1:


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



回答2:


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.




回答3:


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)



来源:https://stackoverflow.com/questions/55535160/how-can-gets-all-tags-and-cucumber-scenarios-without-run-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!