But as a first step we don't need Behat to utilise the Selenium/Sahi/Zombie/PhantomJs drivers, we need Mink.
- Create a BrowserTestBase that is run on top of Mink.
- Use the Goutte driver (pure php) but build the functionality in a driver-agnostic fashion.
- Port some tests as a proof of concept.
Originally Drupal's WebTestBase evolved from SimpleTest but over the years it has morphed and transformed into a mutant beast of difficult to maintain custom code.
Whilst we've been off on our island, the PHP community at large have been working together on solving the same problems we've been adding additional band-aids and bolt-ons to SimpleTest for.
One such solution is Mink.
Say hello to Mink
Many of us are familiar with Behat's gherkin syntax but you may not be aware that the real power of Behat is powered by Mink. Most of the built in step-definitions are added by the Mink extension, which is a Behat Extension that wraps Mink.
The core of Mink is the DriverInterface which allows a swappable back-end for functional testing.
Much of the custom code we have in SimpleTest can be handled by existing functionality in Mink, but in a back-end independent manner.
Since Early April 2014, we have been working on a new functional test base that uses phpunit as the runner and Mink as the browser.
At present in WebTestBase when a test calls
$this->drupalGet() the implementation is hard-wired to use curl.
With BrowserTestBase architected on top of Mink, we maintain a Mink session for browser interactions. The default implementation of this uses the Goutte driver, which is simple web-scraper that wraps Guzzle and the Symfony DomCrawler component. This abstracts away the browser implementation to the various Mink drivers.
So how does this help Drupal?
- We get rid of loads of custom-code for parsing/manipulating the dom and just use widely adopted implementations.
- We get rid of loads of custom Curl handling code and let Goutte and Guzzle worry about it.
- Any issues we find strengthen those code-bases. We've already ported Goutte to Guzzle 4 - i.e. Goutte 2.0. We've found and fixed bugs in Guzzle 4. PIE for the win.
Or in code terms.
$button = $this->getSession()->getPage()->find('css', '#my-button'); $button->mouseOver(); $button->press(); $this->getSession()->dragTo(CssSelector::toXPath('#my-target'), CssSelector::toXPath('#my-destination'));
A) HttpTestBase - Work on creating HttpTestBase that uses Guzzle direct but doesn't need the Mink/DomCrawler elements - for things like Rest and Rss tests - where no browser is required
B) META - Create a meta listing each of the un-converted tests and create issues for each un-converted test
User interface changes
BrowserTestBase is built on top of Mink and PHPUnit so the asserts are different to WebTestBase. Form submits are handled by Mink so instead of
drupalPostAjaxForm() new tests that extend this class will use
submitForm() instead. If the Mink driver supports AJAX it will handle submitting form using AJAX.
How to run
$ cd core $ sudo -u www-data SIMPLETEST_BASE_URL=http://d8.dev ./vendor/bin/phpunit --testsuite functional # Or with run-test $ sudo -u www-data php ./core/scripts/run-tests.sh --url http://d8.dev --class "Drupal\Tests\simpletest\Functional\BrowserTestBaseTest"
Beta phase evaluation
|Unfrozen changes||Unfrozen because it affects automated tests.|
|Disruption||Not disruptive. It adds a new base class which can be used to write browser based tests. Some changes were made to the way Drupal recognizes whether it is running as part of an automated test, but this does not affect existing code.|