Any one know how to use Selenium 2 with Phpunit? Are there any Selenium 2 samples in PHP?
please look at the http://code.google.com/p/php-webdriver-bindings/ . This is PHP library that communicates with Selenium Webdriver server using JsonWireProtocol. This is early version but it works.
I work on selenium2php. I have too many tests for Selenium1 recorded with Selenium IDE. Now it converts html tests into Selenium2. Actually, for PHPUnit_Extensions_Selenium2TestCase. I am going to implement more commands.
I recommened the usage of Menta, a Selenium 2 Framework which requires WebDriver. Both packages are PSR-0 compatible, so you can use them with Composer. You can configure selenium with the phpunit.xml. Here an example
<phpunit bootstrap="tests/bootstrap.php"
backupGlobals="false" backupStaticAttributes="false"
strict="true" verbose="true">
<php>
<var name="testing.selenium.seleniumServerUrl" value="http://localhost:4444/wd/hub" />
<var name="testing.selenium.browser" value="firefox" />
<var name="testing.selenium.windowPosition" value="0,0" />
<var name="testing.selenium.windowSize" value="1280x1024" />
<var name="testing.selenium.windowFocus" value="1" />
<var name="testing.selenium.timeoutImplicitWait" value="10000" />
</php>
<testsuites>
<testsuite name="Integrationstests">
<directory suffix="Test.php" phpVersion="5.3.0" phpVersionOperator=">=">tests/integration</directory>
</testsuite>
</testsuites>
<logging>
<log type="junit" target="build/logs/junit.xml"/>
</logging>
</phpunit>
The bootstrap file reads the configuration variables from testing.selenium.*, so you can easily set new variables.
<?php
\Menta_ConfigurationPhpUnitVars::addConfigurationFile(__DIR__ . '/../phpunit.xml');
$configuration = \Menta_ConfigurationPhpUnitVars::getInstance();
\Menta_SessionManager::init(
$configuration->getValue('testing.selenium.seleniumServerUrl'),
$configuration->getValue('testing.selenium.browser')
);
Now you can easily implement you testcases. Here an example
<?php
namespace tests\integration;
use WebDriver\LocatorStrategy;
class TestSearch extends \PHPUnit_Framework_TestCase
{
public function testGoogle()
{
$session = \Menta_SessionManager::getSession();
$session->open('http://www.google.de');
$element = $session->element(LocatorStrategy::NAME, 'q');
$this->assertTrue($element->displayed());
}
}
The Menta Package also have two demo files, located here
Yes, Selenium 2 (WebDriver)
and PHPUnit tests
is simple. But May I want to gave you advice that the first you should be try Selenium IDE
because you need to expect in selenium command
. If you are expect in Selenium command
if so selenium 2 (Webdriver)
and PHPUnit test
will be more simple for you.
You can try selenium IDE
tutorials on here and you can learn selenium 2 (Webdriver) and PHPUnit
at here.
PHPUnit Selenium integration code lives as a separate project in github, as far as I can see it does not support Selenium 2, so the answer to your question would be - No, you can not use Selenium 2 with PHPUnit.
But you can clone the source tree and make it work with Selenium 2.
I wrote a tutorial about how to use Selenium 2, Facebook wrapper, find it here:
http://testigniter.blogspot.co.uk/2012/01/running-selenium-2-webdriver-using.html