We can use regular expressions in Cucumber for selecting a collection of similar statements in the feature file.
feature file
Feature: Exam Syllabus Scenario Outline: Summer and Winter Exam Schedule Given Exam time table in summer season Given Mathematics and Physics Syllabus Given Exam time table in winter season
The step Definition file has @Given("^Exam time table in ([^\"]*) season$") which maps two Given statements in a Feature file with the help of regular expression.
@Given ("^Exam time table in ([^\"]*) season$") public void timeTable(String season){ if (season.equals("winter")){ System.out.println("The winter syllabus"); }else{ System.out.println("The summer syllabus"); } } @Given ("^Mathematics and Physics Syllabus$") public void syllabusList(){ System.out.println("Mathematics and Physics syllabus is"); }