2014-09-05 17 views
0

是否有無論如何我們可以多次運行相同的測試來驗證功能。如何使用不同的用戶角色多次運行相同的BDD功能

這是我的特點文件:

Feature: End to end tests 

    I want an End to End test pack 
    As Super user and Admin user 
    So that I can ensure that the integrated components of the application function as expected 

    Background: 
      Given I have the login Page 
      When I login to application 
      Then the list is displayed 

    @javascript 
    Scenario: To verify the functionality on the Dashboard   
      When I navigate to the Dashboard Page 
      Then the Dashboard Page is displayed 

我想運行此方案2個不同的用戶。有沒有辦法使用多個用戶/角色來運行相同的功能。

我有幾個其他的特徵文件,這需要使用,我需要在夜間運行

請參考下面的內容檔案2級或3個不同的用戶運行:

public function iLoginToApplication() { 
$page = $this->getSession()->getPage(); 
$page->find('css', '#username')->setValue("admin"); 
$page->find('css', '#password')->setValue("Password"); 
$signInButton->press(); 
} 
+0

有些人會考慮幫助,當你通過所有你的19個問題,並接受答案,補充了你13年的工作經驗。社區花費你知道的時間... – 2014-09-06 21:39:32

+1

我完全理解並欣賞你來自哪裏。我已經接受並評論了相關的人。你可以更具體的 – 2014-09-07 22:45:41

回答

1

是的,可以。直接在Feature: …之下的部分從功能角度來看幾乎沒有用處,並且用作文檔。 AFIAK你可以刪除它或寫任何你想要的東西,你的測試將運行完全一樣。

你在找什麼是scenario outlines,他們的目的就是爲了這個,儘管你需要更新一些你的場景,並且仍然手動指定Examples下的每個用戶。

Feature: End to end tests 

    I want an End to End test pack 
    As Super user and Admin user 
    So that I can ensure that the integrated components of the application function as expected 

    Background: 
     Given I have the login Page 

    @javascript 
    Scenario Outline: To verify the functionality on the Dashboard   
     When I login to application as "<username>" with "<password>" 
     Then the list is displayed 
     When I navigate to the Dashboard Page 
     Then the Dashboard Page is displayed 

    Examples: 
     | username | password | 
     | super | qwerty | 
     | admin | qwerty | 

/** 
* @When /^I login to application$/ 
* @When /^I login to application as "(.+)" with "(.+)"$/ 
*/ 
public function iLoginToApplication($username = null, $password = null) { 
    $page = $this->getSession()->getPage(); 
    $page->find('css', '#username')->setValue(isset($username) ? $username : 'admin'); 
    $page->find('css', '#password')->setValue(isset($password) ? $password : 'Password'); 
    $signInButton->press(); 
} 

另一種方法是在全球範圍內配置此之前運行的套房,例如,通過環境變量與用戶名到PHP當您運行貝哈特,並用不同的配置運行一切幾次。這將是上述解決方案的破綻,並不那麼直觀,所以你最好用Behat的方式來做。

+0

非常感謝答覆。當我們的環境備份並運行時,我將嘗試此解決方案 – 2014-09-09 14:55:00

+0

讓我知道它是否能夠完成這項工作。 – 2014-09-09 15:09:39

+0

嗨伊恩,我試圖使用該解決方案。但問題是在我的上下文文件中使用它。我可以將此作爲參數傳遞給我的上下文文件嗎?請參考上述關於上下文的描述: – 2014-09-09 15:14:42

相關問題