private String [ ] findFeatureByScenarioName ( String scenarioName ) throws IllegalAccessException { List < Description > testClasses = findTestClassesLevel ( parentDescription . getChildren ( ) ) ; for ( Description testClass : testClasses ) { List < Description > features = findFeaturesLevel ( testClass . getChildren ( ) ) ; //Feature cycle for ( Description feature : features ) { //Story cycle for ( Description story : feature . getChildren ( ) ) { Object scenarioType = getTestEntityType ( story ) ; //Scenario if ( scenarioType instanceof Scenario && story . getDisplayName ( ) . equals ( scenarioName ) ) { return new String [ ] { feature . getDisplayName ( ) , scenarioName } ; //Scenario Outline } else if ( scenarioType instanceof ScenarioOutline ) { List < Description > examples = story . getChildren ( ) . get ( 0 ) . getChildren ( ) ; // we need to go deeper :) for ( Description example : examples ) { if ( example . getDisplayName ( ) . equals ( scenarioName ) ) { return new String [ ] { feature . getDisplayName ( ) , story . getDisplayName ( ) } ; } } } } } } return new String [ ] { "Feature: Undefined Feature" , scenarioName } ; }
Find feature and story for given scenario