如何將步驟定義對映到 Cucumber 中的特性檔案中?


我們可以在 Cucumber 中將步驟定義檔案對映到特性檔案。這可以透過以下步驟完成 −

步驟 1− 使用 .feature 副檔名建立一個特性檔案(例如 Login.feature),內容如下 −

特性 − 登入模組

場景 − 歡迎頁面登入驗證

鑑於使用者位於歡迎頁面

那麼歡迎頁面應顯示

步驟 2− 建立 Java 步驟定義檔案(例如 stepDefination.java),它具有步驟定義檔案與特性檔案的對映關係。

示例

package stepDefinations;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
public class stepDefination {
   @Given("^User is on Welcome Page$")
   public void user_on_welcome_page() {
      System.out.println("User on welcome page");
   }
   @Then("^Welcome page should be displayed$")
   public void verify_user_on_welcome_page() {
      System.out.println("User should be on welcome page");
   }
}

專案結構

更新於: 2021 年 11 月 22 日

4K+ 瀏覽量

開啟你的 職業

獲得認證,完成本課程

開始
廣告
© . All rights reserved.