如何在 Cucumber 中使用正則表示式?


在 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("^Exam time table in ([^\"]*) season$"),透過正則表示式的幫助將功能檔案中的兩個 Given 語句對映在一起。

示例

@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");
}

更新於:2020-06-11

4K+ 瀏覽量

開啟你的 職業生涯

透過完成該課程獲得認證

開始學習
廣告