Behat mink测试多个页面

时间:2015-07-10 13:08:18

标签: behat mink

我是新手。 我想要做的是测试一堆页面是否存在。

这是我的例子:

Scenario: Page "contact"
Given I am on "/contact"
Then I should see "contact"
在页脚中,您会看到一个名为contact的链接 所以,如果有一些PHP错误,它退出,我没有看到页脚,所以失败。

但是我可以选择多个这样的名字:

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

1 个答案:

答案 0 :(得分: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));
            }
        }
    }
}