One Mink to rule them all
Published on
Apr 3, 2011
Apr 4, 2011 − You asked for it? You got it! Functional testing has never been so easy...
Tada! Mink 0.1 is here.
But what is Mink? Mink is a browser emulators abstraction layer. It defines basic API through which you can talk with specific browser emulator libraries. Mink drivers define bridge between Mink and those libraries. For now, Mink supports 2 drivers:
- GoutteDriver - Symfony2 BrowserKit+DomCrawler libraries bridge. It covers basic headless browser testing needs and integrates flawlessly with any web application out there, including Symfony2, symfony1, Drupal, Wordpress and others.
- SahiDriver - Sahi framework bridge. This one gives you ability to actually run your tests inside real browsers (Firefox, Chrome, IE, Safari). Think about Sahi as a "much easier Selenium".
Installation
pear install behat/mink
Behat integration
Mink was created specifically for the Behat BDD framework. To give everyone ability to test their complex web applications with Behat.
To integrate Mink into your Behat test suite, you need to do 2 simple steps:
-
Configure
behat.yml
to actually include Behat:default: environment: parameters: start_url: http://your_app_host.loc/
imports: - mink/behat.yml
-
Require Mink and PHPUnit autoloaders inside the
features/support/boostrap.php
script
<?php
require\_once 'mink/autoload.php';
require\_once 'PHPUnit/Autoload.php';
require\_once 'PHPUnit/Framework/Assert/Functions.php';
Now, you're able to use Mink steps inside your Behat features. Check all available steps with:
behat --steps
Or you can specify the steps in your native language. Yes, yes - Mink has step translations for some languages (russian and french by now):
behat --steps --lang fr
By default, all Mink steps will use GoutteDriver
. It means that all your steps will be executed very fast in a headless browser emulator, written by Fabien Potencier.
In-browser testing
But what if you want to actually run/test your features inside a real browser? SahiDriver
comes to the rescue!
Both GoutteDriver
and SahiDriver
are nicely configured out-of-the box in Mink's behat.yml
. So, to switch some of your scenarios to in-browser tester - simply tag them with @javascript
:
<pre class=""> @javascript Scenario: User can login ...
Of course, until you install and start the Sahi proxy, you'll get a Sahi exception saying that the "Sahi proxy is not started". To install Sahi, do the following:
- Go to http://sourceforge.net/projects/sahi/files/sahi-v35/ and download the
sahi_20110213.zip
package. - Unzip the archive into any folder (for example your home root)
- Run
/your/sahi/path/userdata/bin/start_sahi.sh
for Linux and MacOS ORyoursahipathuserdatabinstart_sahi.bat
for Windows. This will start Sahi proxy server.
Now, before any your test suite, you need to start proxy (step 3) and you're done. Mink and Sahi will automatically start the proper browser, when needed ;-)
Changing browser
By default, Mink will use firefox
as the browser to test with Sahi. Of course, Sahi supports different browsers on different OS's (firefox, ie, safari, etc.).
Information about configuring and using different browsers is avaialble in the Sahi documentation.
Changing Mink's browser is as simple as:
default:
environment:
parameters:
start_url: http://your_app_host.loc
browser: ie
imports: - mink/behat.yml
Known limitations and bugs
For now, Sahi has some limitations/bugs on Linux systems. For example, the Sahi proxy doesn't close browser after a test in Linux. Fortunately, Narayan (Sahi developer) is very fast with fixes, and i'm sure we will have a fix for the bug as fast as possible. So, feel free to tell him "thanks" on twitter (@narayanraman) for his great work. Mink wouldn't be possible without his insane project!
Video Screencasts
Mink in Behat
Mink in other testing tools
Mink was created especially for Behat project. But that doesn't mean that you can't use Mink with other testing tools:
Release and documentation
Mink 0.1 is already released and available to everyone from pear.behat.org.
The repository is at Behat GitHub organisation.
Full documentation with use cases will be available tommorow at docs.behat.org.
Comments