2015-07-10 99 views
0

我是新來的behat。 我想要做的就是測試一堆頁面是否存在。Behat水貂測試多頁

這是我的例子:

Scenario: Page "contact" 
Given I am on "/contact" 
Then I should see "contact" 
你看到一個叫做接觸 鏈接頁腳

所以如果有一些PHP錯誤它退出,我沒有看到這樣的頁腳失敗貝哈特。

,但我可以選擇多個名稱如下:

Given I am on [/, /contact, /about-me] etc 

回答

1

你有很多選擇,但我只是讓你們兩個現在這樣比較多,你可以做自己的研究:

這是很多人會做:

特性文件:

Scenario: Checking pages and their content 
Given I am on "/" 
Then I should see "welcome home" 
When I am on "/contact" 
Then I should see "welcome to contact page" 
When I am on "/about-me" 
Then I should see "welcome to about me page" 
When I am on "/whatever" 
Then I should see "welcome to whatever page" 
...... 
...... 

這是驗證文件的物理存在的另一種選擇:

特性文件:

Scenario: Checking pages and but not their content 
Given I am on "/" 
Then I should see "welcome home" 
And the files below must exist in my project folder: 
     | file | 
     | /path/to/my/project/files/contact.tml | 
     | /path/to/my/project/files/about-me.tml | 
     | /path/to/my/project/files/whatever.tml | 

在你FeatureContext文件:

class FeatureContext extends MinkContext 
{ 
    /** 
    * @When /^the files below must exist in my project folder:$/ 
    */ 
    public function theFilesBelowMustExistInMyProjectFoder(TableNode $table) 
    { 
     foreach ($table->getHash() as $file) { 
      if (file_exists($file) !== true) { 
       throw new Exception(sprintf('File "%s" not found', $file)); 
      } 
     } 
    } 
} 
+0

感謝那些非常有意義,現在我有一個想法從哪裏開始 –