Quick update: phpunit does now support Selenium 2
At the time of writing, PHPUnit does not support Selenium 2.
php-webdriver from facebook allows the complete WebDriver API to be called from PHP in an elegant way. To quote:
Most clients require you to first read the protocol to see what's
possible, then study the client itself to see how to call it. This
hopes to eliminate the latter step.
It is used by starting up the Selenium 2 server, which provides the interface at localhost:4444/wd/hub
.
/usr/bin/java -jar /path/to/selenium-server-standalone-2.7.0.jar
then running the PHP test code, which calls that interface. For example:
<?php
require '/path/to/php-webdriver/__init__.php';
$webdriver = new WebDriver();
$session = $webdriver->session('opera', array());
$session->open("http://example.com");
$button = $session->element('id', 'my_button_id');
$button->click();
$session->close();
The WebDriver API is mapped to PHP methods, compare calling click
on element
in the example with the element/click API call in the documentation.
The test code can then be wrapped in regular phpUnit tests.
This is not native phpUnit support, but it's a quite robust approach.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…