Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 2 (WebDriver) and Phpunit?

Any one know how to use Selenium 2 with Phpunit? Are there any Selenium 2 samples in PHP?

like image 603
Paul R Rogers Avatar asked Nov 17 '10 16:11

Paul R Rogers


People also ask

Is PHPUnit a framework?

PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. The currently supported versions are PHPUnit 9 and PHPUnit 8.

Can we use Selenium code in MBL?

Can Selenium be used for mobile testing? Yes, Selenium can be used in combination with Appium for automating website tests on iOS devices. Testing websites on real iOS devices helps teams identify any bugs that an end-user might encounter in the real world.

Can we have multiple drivers in Selenium project?

You can invoke multiple browser sessions by just creating multiple driver objects, and managing them. Each session will be separate if you want them to be.

Does Selenium have multi platform compatibility?

Selenium enables creating the testing suite on any platform and executing the test cases on a different one. For example, the tester could create the test cases using Windows OS, and then run it on a Linux based system. Selenium supports OS X, all versions of MS Windows, Ubuntu and other builds with ease.


1 Answers

Quick update: phpunit does now support Selenium 2

  • https://phpunit.de/manual/3.6/en/selenium.html
  • https://phpunit.de/manual/4.8/en/selenium.html

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.

like image 181
cmc Avatar answered Sep 20 '22 19:09

cmc