Skip to content

Instantly share code, notes, and snippets.

@havvg
Created September 9, 2011 14:44
Show Gist options
  • Save havvg/1206414 to your computer and use it in GitHub Desktop.
Save havvg/1206414 to your computer and use it in GitHub Desktop.
Behavior Driven Development in Symfony2 with Behat, Mink and Zombie.js
@b00gizm
Copy link

b00gizm commented Sep 11, 2011

@havvg

Great detailled tutorial. That'll help a lot of Symfony2 newsbies to get started.
But I think it's worth noticing that the ZombieDriver is best when it comes to Javascript / interaction testing. For "normal" HTML, it's fine to rely on Mink's Goutte driver :)

@cordoval
Copy link

cordoval commented Sep 11, 2011 via email

@everzet
Copy link

everzet commented Sep 11, 2011

What about moving it into https://github.com/Behat/Behat-docs/tree/master/en/cookbook? I want this on docs.behat.org.

@b00gizm
Copy link

b00gizm commented Sep 11, 2011

@havvg
Copy link
Author

havvg commented Sep 11, 2011

@everzet I tried the syntax highlighting, but didn't get it running, what did I miss? https://gist.github.com/1206414/54a7dd83709efe41c2b4a791534c327ba16fe835

@b00gizm Done.

+1 on the cookbook, will fork and rewrite into rst by tuesday.

@everzet
Copy link

everzet commented Sep 11, 2011

@havvg just refactor article into RST and send me a PR into Behat-docs repo (cookbook folder). I'll publish it the same day ;-)

@havvg
Copy link
Author

havvg commented Sep 11, 2011

@everzet Will do so!

@everzet
Copy link

everzet commented Sep 12, 2011

@havvg
Copy link
Author

havvg commented Sep 12, 2011

Awesome :-)

@cordoval
Copy link

when inserting @mink:zombie on the bdd experiment I get errors:

text\FeatureContext::assertElementContainsText()
    And I should not see "Calvin Klein Black, 5"                                # Acme\DemoBundle\Features\Context\FeatureContext::assertPageNotContainsText()
      The text "Calvin Klein Black, 5" appears in the text of this page, but it should not.

5 scenarios (4 passed, 1 failed)
48 steps (47 passed, 1 failed)
0m4.584s

I ran your bdd experiment from the guide in hopes to find a solution to my problem because i was getting

I resolved all things but this one when running zombie:

 Could not load resource for URL 'http://h.local/app_test.php/pickup'

any hints please

appreciate it man @havvg

@havvg
Copy link
Author

havvg commented Sep 13, 2011

I will take a look into this, unfortunately I only ran the listings in zombie so far (just to try).

I tried the feature and get the same error. So it's not your side! Let me check that in details!
Thanks for pointing this out, @cordoval!

@havvg
Copy link
Author

havvg commented Sep 13, 2011

I added a print of the response.

  Scenario: The categories link to their products list
    Given I am on "/categories"
      And I have a product "Calvin Klein Black, 5"
      And I add product "Calvin Klein Black, 5" to category "Underwear"
      And I have a product "Converse All Star, 8"
      And I add product "Converse All Star, 8" to category "Shoes"
     When I follow "Underwear"
     Then I should see "Calvin Klein Black, 5" in the "#product-list li" element
      And I should not see "Converse All Star, 8"
     When I move backward one page
      And I follow "Shoes"
      And print last response
     Then I should see "Converse All Star, 8" in the "#product-list li" element
      And I should not see "Calvin Klein Black, 5"
|  http://bdd.havvgbook/app_test.php/catagories/Shoes
|  
|  <html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|      <link rel="stylesheet" href="/bundles/acmedemo/css/demo.css" type="text/css" media="all">
|      <title>Catalog - Product List</title>
|      <link rel="shortcut icon" href="/favicon.ico">
|  </head>
|    <body>    <div id="symfony-wrapper">      <div id="symfony-header">        <a href="/app_test.php/">          <img src="/bundles/acmedemo/images/logo.gif" alt="Symfony">
|  </a>
|          <form id="symfony-search" method="GET" action="http://symfony.com/search">          <label for="symfony-search-field">
|              <span>Search on Symfony Website</span>
|            </label>
|            <input name="q" id="symfony-search-field" type="search" placeholder="Search on Symfony website" class="medium_txt">
|            <input type="submit" class="symfony-button-grey" value="OK">
|  </form>
|  </div>
|        <div class="symfony-content">        <h1>Product List</h1>
|          <ul id="product-list">          <li>Converse All Star, 8</li>
|  </ul>
|  </div>
|  </div>
|  </body>
|  </html>

The response looks fine, seems the assertion is done on the wrong string.

@havvg
Copy link
Author

havvg commented Sep 13, 2011

I didn't find the cause by now.

In Behat\Mink\Behat\Context\BaseMinkContext::assertPageNotContainsText() the $actual variable contains the text from the previous response, not that of the current.
By adding the "I reload the page" step, it works with Zombie. My guess so far, the ZombieDriver or Zombie.js itself has an issue with the "move back" + "follow" steps.

  @mink:zombie
  Scenario: The categories link to their products list
    Given I am on "/categories"
      And I have a product "Calvin Klein Black, 5"
      And I add product "Calvin Klein Black, 5" to category "Underwear"
      And I have a product "Converse All Star, 8"
      And I add product "Converse All Star, 8" to category "Shoes"
     When I follow "Underwear"
     Then I should see "Calvin Klein Black, 5" in the "#product-list li" element
      And I should not see "Converse All Star, 8"
     When I move backward one page
      And I follow "Shoes"
      And I reload the page
     Then I should see "Converse All Star, 8" in the "#product-list li" element
      And I should not see "Calvin Klein Black, 5"

@cordoval
Copy link

just for the sake of others that may run into this situation some more on Zombie pitfalls you may encounter http://www.craftitonline.com/2011/09/zombie-pitfalls-part-ii/

update: work around does not work for all cases, I continue to see errors ahead of the run

@leftdevel
Copy link

Hi guys.
Im having the same Cordoval issue for the zombie driver:

text\FeatureContext::assertElementContainsText()
    And I should not see "Calvin Klein Black, 5"                                # Acme\DemoBundle\Features\Context\FeatureContext::assertPageNotContainsText()
      The text "Calvin Klein Black, 5" appears in the text of this page, but it should not.

5 scenarios (4 passed, 1 failed)

I'm using symfony2 beta3 with this config for composer:

        "behat/behat":  "2.4.*@stable",
        "behat/mink":   "1.4.*@stable",

        "behat/symfony2-extension":      "*",
        "behat/mink-extension":          "*",
        "behat/mink-browserkit-driver":  "*",
        "behat/mink-selenium2-driver":   "*",
        "behat/mink-zombie-driver":   "*"

I've tried to use default_session:symfony2, and use the @mink:zombie annotation, also just leaving the default_session:zombie.

Any advice? Thanks.

@havvg
Copy link
Author

havvg commented Jul 19, 2012

Did you try the reload step?

I'm not exactly sure, but I believe the issue is somewhere within Zombie.js.
There are even more issues with Zombie.js. That's why we switched to Sahi. It's not as fast, but by our experience with both variants way more reliable

@cordoval
Copy link

@cordoval is a like minded individual

@leftdevel
Copy link

Hi again.
As @havvg suggested, putting a "And I reload the page" seems to work, the odd thing is that this needs to be put after each "When I move backward one page".

Seems a bug to me. Should I rely on this trick or should I move to another driver? Saphi?

Many thanks.

@cordoval
Copy link

That's why we switched to Sahi.

@leftdevel
Copy link

Oh. Thanks. I was writing at the same time as you guys, now I notice your comments.
Thanks. I think I will make the switch to Sahi; I think it is not safe to rely a serious project with this kind of bug + workarounds :D

Many thanks.

@b00gizm
Copy link

b00gizm commented Jul 19, 2012

The problem is that the development of Zombie.js went very fast in the last few month with a lot of refactoring and new internal libraries. It's pretty hard to keep up with all the compatibility issues, especially when you can only spent a pretty small amount on your time on your open source projects :-/

In my experience, everything below v0.13.0 works pretty well with the current version of the ZombieDriver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment