Search code examples
phpsymfonyseleniumbddbehat

Behat Scenario Registration - not finding text


I have a very strange behaviour at a very basic scenario i've written. When not running the scenario with "@javascript" tag and selenium server, behat always fails and tells me that the specified text could not be found. But when I put @javascript, start selenium server and run the scenario again, everything passes. The site it is testing is just a basic registration site that gets submitted via post, and when registration is completed, the user gets redirected to "/register/success", where the message is displayed on the screen. When I do not run with selenium, the user does not even get saved in the database and the test fails due to missing text.:

@javascript // <-- only passing when adding this and starting selenium
Scenario: Fill in correct fields and register user
Given I am on "/register"
When I fill in the following:
  | Username        | usernotreserved         |
  | Email           | test@web.com            |
  | Password        | test1234!               |
  | Repeat password | test1234!               |
And I press "Register"
Then I should see "The user has been created successfully" 

I've also tried the scenario manually by filling out the form and the user gets registered and saved in the database correctly.

Running Behat v3 on PHP7.

Running behat with -vvv gives the following output:

behat -vvv output

The huge error is not being shown when running with "javascript".

Behat.yml file:

extensions:
 Behat\Symfony2Extension: ~
 Behat\MinkExtension:
  base_url: "http://127.0.0.1:8000"
  goutte: ~
  selenium2: ~
  sessions:
    default:
      symfony2: ~

I think the best option would be to always use "@javascript", because then I don't need to worry about finished page loads..?


Solution

  • Use

    Then print last response
    

    or

    Then print current URL
    

    (put it after And I press "Register")

    also

    run behat with -vvv flag.

    Maybe the url is pointing to wrongly configured env like app_test.php in normal behat scenario, or you have some js that prevents from normal page processing?