Adventures in Behat with Mink - Implicit Wait

Submitted by allan on Wed, 10/10/2012 - 21:39
Just a quick blurb about some of the "supposed to be" easy stuff with Mink in Behat. If you don't know, Mink is a common api for several different interface testers such as Selenium Webdriver, HtmlUnit, and Goutte. It's beautiful because you can switch between frameworks and generally the commands you issue to one driver will work on a different driver. However, it's more about being able to use one driver and then a different one and what not to speed up your tests and facilitate your needs! Also, Behat is a project that brings Gherkin to PHP. As most of you know, I'm a pretty avid php developer and haven't gotten around to Ruby, which is where the origins of Behat, Cucumber, was created. This creates a common test case between everyone involved in the feature, making it idea so that less work has to be don. With all that said, I come from a PHPUnit Selenium RC world, where you have commands such as clickAndWait, and waitForPage, and what not. Well, my inters and I found that this wasn't the case when dealing with the Webdriver framework that comes with Mink. Our problem was that now things didn't "implicitly wait". Even our finds on elements were dying occasionally because things were just moving too fast! After a lot of studying java code and finally finding some simular php commands I found the answer to our waiting problems. There is a command called implicit timeout
What this does is basically sets around a maximum of 5 seconds for whatever to happen and if it doesn't... then we fail... not before though. The array sent as a parameter is converted to JSON. Without that knowledge, I doubt I would have ever figured out the answer. Now that I've got it working it seems so straight forward, even though the framework seems to rely solely on magic to work. Some of the tihngs we take for granted.