2012-03-27 53 views
1

我有以下情形的:貝哈特步驟定義有時執行有時不

@wip 
Scenario: Attempt to get account information of an activator without credentials 
Given an activator with e-mail "[email protected]" and password "testpassword" already exists 
When I send a GET request to "/activators/1" 
Then the response code should be 401 

@wip 
Scenario: Attempt to get account information of another activator then myself 
Given an activator with e-mail "[email protected]" and password "testpassword" already exists 
And an activator with e-mail "[email protected]" and password "testpassword" already exists 
And I am authenticating as "[email protected]" with "testpassword" password 
When I send a GET request to "/activators/1" 
Then the response code should be 401 

數據庫每隔方案之前下降,從架構重新創建。

步驟'給予激活器...'將新用戶插入到數據庫中。
但是!它並不總是爲兩個用戶做到這一點。

這是分步實施:

/** 
* @Given /^an activator with e-mail "([^"]*)" and password "([^"]*)" already exists$/ 
*/ 
public function anActivatorWithEMailAndPasswordAlreadyExists($email, $password) 
{ 
    $activatorManager = $this->getContainer()->get('am.manager.activator'); 
    #$logger = $this->getContainer()->get('logger'); 
    #$logger->debug("Email: $email, password: $password"); 
    $activator = $activatorManager->createActivator($email, $password); 
    $activatorManager->save($activator); 
} 

現在奇怪的事情:
在這最後一步,我應該得到兩個插件:一個用於dietervds,eviltwin之一。

我得到了兩個插件,當我:

  • 只運行一個場景
  • 輸出的東西在日誌(創建「記錄儀」沒有幫助,我需要輸出的東西我沒有按輸出。 「T必須是動態的,它可以只是一個固定的字符串)

我只得到一個接插件(適用於dietervds)當我:

  • 運行兩個方案一起
  • 或當我在步實施

不輸出任何記錄,我完全被這個困惑。
有沒有明顯的缺失?可能是步驟定義中的某種緩存問題? (日誌可能會更改簽名什麼的,不知道)

歡迎任何的反饋:-)

乾杯!

Dieter

回答

1

這一步def做ajax調用嗎?

當我發送一個GET請求到「/激活/ 1」

如果這樣做,你可以嘗試加入一些等待時間在那裏給你的DOM的時間來加載結果

當你用press或跟隨鏈接提交表單或者去重定向瀏覽器時,Thens的工作效果最好,該瀏覽器啓動一個完整的請求響應循環,觸發機器人等待新的dom加載。

與ajax不完全相同的方式發生。

如果你不這樣做的AJAX,我建議你只使用內置的

When I follow "/activators/1" instead 

一步DEFS有一種方法,以防止緩存在YAML配置。下面是我們使用的鍍鉻爲例配置,但它應該工作相同的任何瀏覽器驅動器

default: 
    extensions: 
     Behat\MinkExtension\Extension: 
      base_url: https://yurwebsite.com 
      goutte: ~    
      browser_name: "googlechrome" 
      selenium2: 
       capabilities: { "browser": "googlechrome", "version": "23", "applicationCacheEnabled": false } 

最後布爾PARAM確實爲我們的瀏覽器緩存的伎倆發出

+0

感謝您的答覆mugafuga! 我很確定它沒有實際執行AJAX調用。但不幸的是,我再也不能檢查了。也許你的回答會幫助一個有類似問題的人。 – Dieter 2013-01-11 11:17:50