BDD, Behat, Mink and other Wonderful Things

Looking for Behat v2.5 of the tutorial? See https://knpuniversity.com/screencast/behat-v25.

Behat is my absolute favorite library to use. First, it let's me think about the behavior of my features first, before I start developing. In this tutorial, we'll do that, and it'll change the way you develop. Second, Behat turns that written behavior into functional tests against your application. Does your feature behave correctly? Just run the automated robots to find out!

Along the way, we'll master Mink - the partner library to Behat - and solve all sorts of common problems, like:

  • Running scenarios in a real browser
  • Properly waiting or JavaScript events
  • Leveraging Behat hooks
  • Multiple contexts
  • Loading Database fixtures and clearing data
  • Bootstrapping your application (specifically Symfony)
  • Using the authenticated user
  • Tagging scenarios
  • How to put BDD into practice
  • Keeping the velociraptors in their pen.

Let's do this!


Your Guides

Ryan Weaver Leanna Pelham

Questions? Conversation?

  • 2016-07-18 Diego Aguiar

    Hey Ryan!
    Thanks for your answer

    I ended doing your solution A ;]

  • 2016-07-15 weaverryan

    Hey guys!

    You're doing the right thing - but you need to use a JavaScript-based driver if you want to do this. The reason is that a button (except for a submit and reset button) has *no* functionality outside of JavaScript. What I mean is: if I click a "submit" button, it submits a form. But if I click your button (in an environment that has no JavaScript), nothing will happen: this button has no native functionality. The Symfony2Extension is basically trying to warn you about this.

    So, solutions:

    A) Don't click this button :). If you're clicking it simply so that a drop-down can open and you can click a link/button that's *inside* of that drop-down, you can simply skip clicking this first button and click/press the "hidden" link/button directly. Of course, you can't do this in a "real browser" (because the link/button is hidden), but you can with the Symfony2Exension - because it's simply parsing the HTML and can click/press any button you want.

    B) Use a JavaScript-based driver (like Selenium).

    Both are good solutions - (A) feels like cheating, but I don't think it is - I'm not worried about testing that the drop-down works, so it's cool to skip it if you want.

    Cheers!

  • 2016-07-15 Diego Aguiar

    Hello Victor

    I just can't imagine why symfony's driver don't support clicking on button tags, but well ... thanks for your reply ;]

  • 2016-07-14 Victor Bocharsky

    Hey Diego,

    In your case I simply replace a button `<button type="button">` tag with a link `<a href="javascript:void(0);">` tag. If you use Twitter Bootstrap - this link will exactly look like a button. But I'm wondering about other solutions here too )

    Cheers!

  • 2016-07-13 Diego Aguiar

    Hey there!
    I found this tutorial really good, I really appreciate your effort doing it.
    Also a I have a question :]

    How do you press a button tag using symfony-extension driver ?
    I'm getting this error over and over(I'm going crazy) - Behat\Symfony2Extension\Driver\KernelDriver supports clicking on links and submit or reset buttons only. But "button" provided

    My step is - When I press "Actions" from MinkExtension class, method pressButton($button)
    And my html is like this:
    <button data-toggle="dropdown" type="button" class="btn btn-default dropdown-toggle">
    Actions
    </button>

    Thanks in advance

  • 2016-03-22 Dan Costinel

    I still experience an error when testing. Do you know why my test fails? http://imgur.com/Ts6E3w1

  • 2016-03-22 Dan Costinel

    Nevermind guys. I've missplaced the security. Instead of putting it in app/config/security.yml, I've placed it in app/config/config.yml... Sorry!

  • 2016-03-22 Dan Costinel

    Hello guys. I copied all the "finish" files into a fresh Symfony 2.7.10 project. I changed few things in your files, in order to make the project work, and I finally did it. Now I'm stuck at login, as I can't login with the provided credentials (user=admin, pass=admin). I've re-created the db with the link inside my app ( /_db/rebuild ) - nothing, I've deleted entirely my db, and I've re-created it with doctrine:database:create, and doctrine:schema:update --force, but still nothing. I get the same error message when I try to login: Invalid credentials. I tried to generate, online, the bcrypt hash for the string "admin" using http://bcrypthashgenerator.app..., and replacing the password field value within user table, but without any good result. Any ideas on how to solve it, maybe without re-creating all from the start? Thank you!!

  • 2016-01-19 weaverryan

    Hi Bartek!

    Yes, I have done this stuff before with a client (at least with iframes, but I think also with windows) - some of the details are fuzzy, but we were totally able to pull it off. As you probably already know, the key methods are on the Session: https://github.com/minkphp/Min.... I would use getWindowName() and getWindowNames() (https://github.com/minkphp/Min... to debug and figure out what all the window names are being called during the process.

    I know that's vague, but I hope it helps! Cheers!

  • 2016-01-19 Bartek

    Hi, How can I switch from one window to another. For example, my scenario is as follows -

    Scenario Outline: User login with Facebook
    When I press "siginFacebook"
    And I switch to the new tab
    And I fill in "<email>" for "email"
    And I fill in "<password>" for "pass"
    And Click the "u_0_2" select by "id"

    In this stage, as facebook login works, so popup window close automatically and it generates an error -
    "Window not found. The browser window may have been closed."

    Do you know how to come back to my original window after a successful facebook login?

  • 2015-10-13 weaverryan

    Hey!

    If you own the Behat 2.5 version, shoot us an email/contact message and we'll be happy to give anyone a coupon code to grab the 3.0 version free :).

    Cheers!

  • 2015-10-13 truthrevealer

    Should the owners of Behat 2.5 course purchase this one as well to get access to it?

  • 2015-10-13 Richard Bagshaw

    So much yes!! I want this one :) Behat 3!! :)