2016-05-31 62 views
0

我的問題是關於BDD(Specflow)的最佳實踐。 在我測試的web應用程序中,我必須編寫一個關於創建合同的功能。使用Specflow的最佳方式

要創建合同,用戶必須通過8個選項卡,並且對於每個選項卡用戶將輸入超過15個值(最小值4,最大值40)。

我的命題是

Given Go to the screen "Contrats" 
    And Click on the button "New contract" 
    When Enter in Tab1 
    | Field1  | Field2  | Field3 | 
    | -----------| ------------| ----------| 
    And Click on the Next button 
    And Enter in Tab2 
    | Field1   | Field2  | 
    | --------------- | -----------| 
    And Click on the Next button 
    And Enter in Tab3 
    | Field1 | Field2 | Field 3| Field4 | Field5 | Field6 |Field7   | 
    | -------| -------| ------ | -------- | --------- | -------| ----------------| 
    And Click on the Next button 
    And Enter in Tab4 
    | Field1 | Field2 | Field 3| Field4 | Field5 | Field6 |Field7   | Field8| 
    | -------| -------| ------ | -------- | --------- | -------| ----------------| ------| 
    And Click on the Next button 
    And Enter in Tab5 
    | Field1 | Field2 | Field 3| Field4 | Field5 | Field6 
    | -------| -------| ------ | -------- | --------- | -------| 
    And Click on the Next button 
    And Enter in Tab6 
    | Field1  | Field2  | Field3 | 
    | -----------| ------------| ----------| 

    And Click on the Next button 
    And Click on the Next button 
    And Cliquer sur Oui 
    And Enter in Tab7 
    | Field1  | Field2  | 
    | -----------| ------------| 
    And Click on confirm enregistration 
    And Save the contract reference and close the popup 
    And Click on button No 
    Then Redirecting the Summary tab 

所以在這種情況下爲每個標籤我必須對模型爲例:

public class Tab1{ 
    public string Field1 { get; set; } 
    public string Field2 { get; set; } 
    public string Field3 { get; set; } 
    } 

問題: 在這個功能我是嘗試只輸入必填字段。 但是在其他功能中,我必須輸入更多的字段,所以在Tab1中,我將輸入例如37個字段。 我可以在這種情況下,這樣做:

創建另一種模式?:我有太多的車型

2- 創建領域的最高只是一個模型,併爲第一種情況我會爲其他戰隊設置一個空值(Field4-> Field37):模型的屬性太多。

3-爲TAB1的每一個集團,我們創建類,如:

public Class Tab1{ 

    public Bloc1 Field1 { get; set; } 
    public Bloc2 Field2 { get; set; } 
    public Bloc3 Field3 { get; set; } 


    public class Bloc1{ 
    public string Field1 { get; set; } 
    public string Field2 { get; set; } 
    public string Field3 { get; set; } 
    } 

    public Class Bloc2{ 
    public string Field1 { get; set; } 
    public string Field2 { get; set; } 
    public string Field3 { get; set; } 
    } 
    . 
    . 
    . 
} 

但是這種解決方案我怎麼能寫我的功能?

回答

0

即使我面臨與我的測試數據相同的問題。我需要爲每個測試傳遞20到30個字段,因爲它包含端到端工作流程。如果你使用的表,因爲你需要創建的表類爲每組輸入值(在你的情況TAB1,TAB2等)

您可以使用Scenatio外形而不是方案通過這將是非常困難的輸入值。請參閱下面的示例:

# Basic Login check 
# Verifies whether user is able to login or not 
Scenario Outline: REG - Login Check 
Given I have logged in using "<username>" and "<password>" 
When I should see my username after login 
Then I will logout of Echo 
Examples: 
| username   | password   |Field1|Field2|Field3|Field4|Field5| 
| lee kirby-walker | LKirby-Walker10* |input1|input2|input3|input4|input5| 
| sample 1   | pwd1    |input6|input7|input8|input9|input10| 

您可以將任意數量的測試數據行傳遞給測試。但是它在VS中創建了很多測試用例。這些測試數據值將作爲參數傳遞給步驟定義方法。

請參見下面的步驟定義爲一步鑑於我在使用「用戶名」和「密碼」

 [Given(@"I have logged in using ""(.*)"" and ""(.*)""")] 
     public void LogInUsingUsernameAndPassword(string userName, string password) 
     { 
      ScenarioContext.Current["userName"] = userName; 
      UserHomePage = LoginPage.Login(userName, password); 
      Reporter.ReportNote(string.Format("User {0} logged in successfully", userName), Status.Pass); 
     } 

但隨着方案大綱必須使用例子已經登錄否則specflow會拋出一個錯誤。

+0

我想你不明白我的問題,因爲在這裏我沒有試圖用多個例子來測試一些東西,但這只是一個例子,但我必須測試的網頁包含多個字段。但你說的是我只有2個字段的用戶名和密碼,我想用多個例子來測試這兩個字段。 – user3446229

+0

我提供的僅僅是一個例子。您可以根據需要添加儘可能多的測試數據字段。像用戶名和密碼一樣,你可以添加Field1,Field2,Field3等。我已經使用了20多個字段來測試。如果你想要,你可以使用不同組的測試數據進行相同的測試。如果沒有,只需使用一套。 –

+0

也是同樣的問題,在這裏你將如何實現解決方案,這一步。在我的情況下,我不是seraching使用**示例**只是一行,但我面臨的問題是在那之後,當我將實現此解決方案我有義務使用一個有5個字段的列表,我的問題是關於數字而不是輸入。 – user3446229