簡體   English   中英

如何在 Cucumber 特征文件中創建 data.table 以及我的場景的步驟定義

[英]How to create data table in Cucumber feature file and step definition for my scenario

假設我在 UI 應用程序中的條件,取決於我需要驗證條件列的階段和狀態。

筆記:

  • 訂單將重新安排
  • 數據必須從 cucumber 特征文件傳遞

如何在步驟定義中編寫代碼?

SlNo Stage Status Condition
------------------------------
1     p      d       True
2     p      d1      True
3     p      r       True
4     p      r1      False
5     v1     f       True
6     v1     s       False
7     v1     c       True
8     v1     a       True
9     v1     a1      False
10     v2     f      True
11     v2     s      False
12    v2     c       True

我直接使用 if 和 elseif 條件在步驟定義文件中應用了階段和狀態

Output:我是對的,但我想通過使用 Cucumber 特征文件將數據傳遞到步驟定義。

注意:在 UI 中數據將被重新排列(它不會保持相同的順序)。

例子:

  | slno |stage|Status|Condition|
  | 1    |p    |d     |True     |
  | 2    |p    |d1    |True     |
  | 3    |p    |r     |True     |
  | 4    |p    |r1    |False    |

if(Cucumber_p == (Cucumber_d||Cucumber_d1||Cucumber_r){
 sa.assertThat((boolean) Cucumber_Condition).isTrue();
}
else if(Cucumber_p == Cucumber_r1){
 sa.assertThat((boolean) Cucumber_Condition).isFalse();
}
else if(Cucumber_v1 == (Cucumber_f||Cucumber_c||Cucumber_a){
 sa.assertThat((Boolean) Cucumber_Condition).isTrue();
}
else if(Cucumber_v1 == (Cucumber_s||Cucumber_a1){
 sa.assertThat((boolean) Cucumber_Condition).isFalse();
}

您輸入的 In.feature 文件(例如):

Given I have a table
|SlNo| Stage| Status| Condition|
| 1  |  p   |   d   |    True  |
...
(fyi, you may keep the header or skip)

然后,在您使用 DataTable 的方法中:

@Given("I have a table)
public void workWithTable(DataTable dataTable) {
for (int i = 0; i <= datatable.height(); i++) /*if you have header, 
                                                    you start with 1*/
   string slNo = dataTable.cell(0, i);
   string stage = dataTable.cell(1, i);
   /* etc..., so you may build a List using these data or use the 
                info as you wish*/
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM