我们可以在Cucumber中使用正则表达式来选择功能文件中相似语句的集合。
功能文件
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
步骤定义文件具有@Given(“([^ \”] *)season $“)中的@Given时间表,该表在正则表达式的帮助下将两个Given语句映射到Feature文件中。
@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"); }