Laura_E's avatar

Behat "I should see 'Laravel 5'" test fail homepage

In my new Laravel application (created by $ composer create-project laravel/laravel my_app), I type:

$ php -S localhost:8888 -t public

And in the browser (Safari or Chrome) on localhost:8888 I successfully see black text "Laravel 5" on the webpage.

I have a hometest.feature file in features/ that looks like:

Feature:
  In order to prove that Behat works as intended
  We want to test the home page for a phrase
  Scenario: Root Test
    When I am on the homepage
    Then I should see "Laravel 5"

I also have a /features/bootstrap/FeaturesContext.php file.

The localhost is not currently running when I run:

$ vendor/bin/behat

The console output is:

Feature:
  In order to prove that Behat works as intended
  We want to test the home page for a phrase

  Scenario: Root Test             # features/hometest.feature:5
    When I am on the homepage     # FeatureContext::iAmOnHomepage()
    Then I should see "Laravel 5" # FeatureContext::assertPageContainsText()
      The text "Laravel 5" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)

--- Failed scenarios:

    features/hometest.feature:5

1 scenario (1 failed)
2 steps (1 passed, 1 failed)
0m0.12s (20.26Mb)

Why does my simple "I should see 'Laravel 5' test fail? If the localhost needs to be running, how do I run my test at the same time? When I start up the local host, nothing I type in the terminal receives a response anymore. Thank you!

0 likes
1 reply
Xanthakita's avatar

Hi Laura, there are two ways (at least you can do this... one is preferable to the other.

  1. run your localhost command in one terminal and open a second tab or window to run behat.
  2. run your localhost command in the background (append & at the end of the command.) the problem with that is you have to remember the process id so you can kill the process later...

Another method that I have started using is laravel valet valet allows you to simply configure a base directory which then servers as your hosting platform... (not saying that correctly... for example I have valet pointing to my ~/repos directory in repos I have a folder called laravel-test (for example) all I have to do is go to my browser and enter the url laravel-test.dev and the page loads. Using this with behat I have to change the base url to match etc... hopefully this helps

Please or to participate in this conversation.