Search code examples
behatmink

Behat mink test multiple pages


I'm new to behat. what I want to do is test a bunch of pages if they exist or not.

this is my example:

Scenario: Page "contact"
Given I am on "/contact"
Then I should see "contact"

in the footer you see a link called contact so if there is some php error the it quits and I don't see the footer so behat fails.

but can I select multiple names like this:

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

Solution

  • You have many options but I'm just giving you two for now so for more, you can do your own research:

    This is what many people would do:

    Feature file:

    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"
    ......
    ......
    

    This is another option which verifies physical existence of the files:

    Feature file:

    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  |
    

    In your FeatureContext file:

    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));
                }
            }
        }
    }