![](/img/trans.png)
[英]Nightwatch/Cucumber - Scenario Outline and Example table not working
[英]Cucumber tests - break example table of scenario outline into smaller chunks
我在方案大綱中有一個很大的示例表,大約有20列
Scenario Outline: ....
Given ....
When ...
Then ....
Examples:
|col1|col2|col3|col4|col5|........|col20|
|val1|val2|val3|val4|val5|........|val20|
是否可以將示例表拆分成較小的塊,像這樣
Examples:
|col1|col2|col3|col4|col5|
|val1|val2|val3|val4|val5|
|col6|col7|col8|col9|col10|
|val6|val7|val8|val9|val10|
....upto 20
示例表的每一行表示一個方案運行。 如果將行分開,則每個方案大綱運行中的某些值將沒有值,並且您將有更多運行,而實際需求除外。 所以答案是否定的。
您可以嘗試將所有數據或功能文件外部的某些數據存儲在excel文件甚至數據庫中。 excel或db將具有一個唯一的鍵列,該鍵列需要與示例表中的行索引匹配。
功能文件-
Given Data is stored in file located at //project/module/data/bigscenario.xlsx and use index <DataRowIndex>
Given
When
Then
Examples:
| DataRowIndex |
| 1 |
| 2 |
| 3 |
| 5 | //Even skip index so 4 will not run
StepDefinition代碼-
private static boolean dataFlag = false;
private static Map<Integer, DataObject> data = new HashMap<>();
private int rowindex;
@Given("^Data is stored in file located at (.*?) and use index (.*?)")
public void getData(String path, int rowindex) {
if(!dataFlag) {
//Access data from excel using apache poi or db code, and store in map as dataobjects.
dataFlag = true; //Data access runs only for first scenario run.
}
this.rowindex = rowindex; //Key to get data for scenario from map
}
這有其優點和缺點。 您正在從功能文件中分離數據。 介紹方案中的技術細節。 逐步失去數據匹配和轉換的能力。 主要的專業數據是可管理的。
一種方法是將gherkin與qaf一起使用,其中它支持外部文件excle / csv / xml / json或數據庫中提供的示例。 在這種情況下,您的情況可能類似於:
Scenario Outline: ....
Given ....
When ...
Then ....
Examples:{'datafile':'resources/testdata.xls'}
如果您想在單個場景中使用許多示例處理大量數據,則可以執行以下操作
編寫一個場景,討論將foo_data作為單個實體
Given ... When I bar with foo_data Then I should see no foo_data errors
編寫一個呼叫步驟定義以處理所有數據
When "I bar with foo_data" do bar_with_foo_data end
在輔助方法中寫入所有文件處理數據之類的東西
def bar_with_foo_data items = import file ... items.each do |item| bar_with item: item ... end
您在這里所做的事情是將測試運行的細節簡化為代碼,而不是Cucumber。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.