2012-03-27 47 views
2

在一個功能文件中有一個Background和幾個場景,但現在需要一個與不需要運行後臺邏輯的相同功能相關的場景,可以僅爲一個場景禁用?BDD - Cucumber:可以禁用功能中僅一個場景的後臺邏輯?

更新 - 添加實例:

Feature: Sign Up 

    In order to access to protected parts of site 
    A user 
    Should sign up 

    Background: 
    Given I am on sign up page 
    And I am not logged in 

    Scenario: User sign up succesfully 
    When I sign up with valid fields 
    Then I should view dashboard page 

    Scenario: User altredy sign up 
    When I sign up with altredy registred user e-mail 
    Then I should view altredy sign up message and link to forgot password page 

    Scenario: User try to sign up with missing/wrong data 
    When I will try to sign up with missing/wrong data 
    Then I should error message 

    Scenario: User altredy sign in 
    #here disable background 
    Given I am logged in 
    When I am on sign up page 
    Then i should be redirect to dashboard page 
+0

遺憾的是沒有必要。 – p0deje 2012-03-28 12:39:45

+1

幸運沒有。 – iafonov 2012-03-29 10:54:34

+0

@iafonov爲什麼?已經添加了一個思想有用的片段... – byterussian 2012-03-29 21:50:51

回答

0

我會得到完全消除的背景條款 - 這是不必要的細節。沒有它,你的場景就會變得完美。

您可以訪問註冊頁,並驗證該用戶尚未登錄,因爲你的「當我簽署了有效的域」步驟定義的一部分。

0

解決方法1.

你可以把只有場景在其他功能文件,其中有沒有背景,或者它有它自己的背景

解決方案2.

取下特徵文件的背景和然後把它的邏輯上的步驟定義,像

Given 'I am on sign up page' do 
    some code here 
end 

Given 'I am not logged in' do 
    some code here 
end 

然後在第一個步距

Given 'I sign up with valid fields' do 
    step 'I am on sign up page' 
    step 'I am not logged in' 
    the rest of your code for this step 
end 

Given 'I sign up with altredy registred user e-mail' do 
    step 'I am on sign up page' 
    step 'I am not logged in' 
    the rest of your code for this step 
end 

Given 'I will try to sign up with missing/wrong data' do 
    step 'I am on sign up page' 
    step 'I am not logged in' 
    the rest of your code for this step 
end 

雖然你會重複這些至少3次,但這並不美觀。

解決方案3.

你可以擺脫那種情景,並將其粘貼在第一種方案中的步驟,像

Scenario: User sign up succesfully 
    When I sign up with valid fields 
    Then I should view dashboard page #this is your Given I am logged in step 
    When I am on sign up page 
    Then i should be redirect to dashboard page 
0

你爲什麼不創建一個步驟定義封閉該會話? 是這樣的:

Then(/^I close the browser$/) do 
    page.driver.quit 
end 

然後你做任何你在你的後續步驟

相關問題