Automation testing using integration of Selenium, PHPUnit, Ant and create reports

Prerequisites for the integration of automation suit Selenium, PHPUnit and Ant are as below-

Install Ant

Download ant from “zip” file for windows.
Follow all the steps for installation and  also optionally install the libraries as mentioned

Automation testing using integration of Selenium, PHPUnit and Ant

Run Selenium through command prompt as mentioned in one of the article above.

Create a folder “runtests”  under your project directory some where on the file system.

This “runtests” folder will contain all the selenium test case files generated through Selenium IDE.

Create AllMyTests.php file under runtests folder. This configures phpunit to execute all the files under runtest folder.  Source code provided below.

Create build.xml file under your project directory adjacent to rntests folder.

On Command Prompt run/execute the following command in this folder (make sure ant is configured, test ant -version on command prompt to check)-
>ant build

This will read build.xml file and execute all the selenium test cases. Source code for build.xml is provided below.


<!– This project launches the test generator and execute all phpunit selenium tests –>
<project name=”proj” default=”build” basedir=””>
<!–Get environment variables –>
<property environment=”env” />
<property name=”logFolder” value=”${basedir}\logs”/>
<property name=”testFolder” value=”${basedir}\runtest”/>

<property name=”test” value=”**” />
<condition property=”pattern” value=”runtest/*.php”>
<os family=”windows” />


<!– Check Operating system to set phpunit path–>
<target name=”check_os”>
<condition property=”isWindows”>
<os family=”windows” />
<condition property=”isLinux”>
<os family=”unix” />

<target name=”if_windows” depends=”check_os” if=”isWindows”>
<property name=”exe.phpunit” value=”C:\wamp\bin\php\php5.2.9-2\phpunit.bat” />

<target name=”if_unix” depends=”check_os” if=”isLinux”>
<property name=”exe.phpunit” value=”${env.PHP_HOME}/includes/PHPUnit-3.2.0/PHPUnit” />

<target name=”prepare” depends=”if_windows, if_unix”>
<mkdir dir=”${logFolder}”/>

<target name=”phpunit”>
<!– Check if folder empty –>
<fileset id=”fileset.test” dir=”${testFolder}”>
<include name=”*.*”/>
<fail message=”Files not found”>
<resourcecount refid=”fileset.test” when=”less” count=”1″></resourcecount>
<!– Execute phpunit tests –>
<exec executable=”${exe.phpunit}” failonerror=”true” dir=”runtest”>
<arg line=”–verbose –testdox-html ‘${logFolder}/phpunit-report-${TODAY}.html’ –no-syntax-check –filter ${test} AllMyTests” />

<target name=”build” depends=”prepare,phpunit”/>

AllMyTests.php file under “runtest” folder

define(‘PATTERN_OF_TEST_FILES’, ‘-test.php’);


function autoloader_for_tests($c)
$location = getLocationForClassName($c);
if (!empty($location))

class AllMyTests
public static function main()

public static function suite()
ini_set(‘memory_limit’, ‘200M’);

$phpunitsuit = new PHPUnit_Framework_TestSuite(‘PHPUnit Framework’);

$files = new FilterTheDirectory(dirname(__FILE__));

foreach($files as $file_name)

$phpunitsuitName = str_replace(PATTERN_OF_TEST_FILES, ”, $file_name);
return $phpunitsuit;

class FilterTheDirectory extends FilterIterator
public function __construct($path)
parent::__construct(new DirectoryIterator($path));

public function accept()
return strpos($this->getInnerIterator()->getFilename(), PATTERN_OF_TEST_FILES) !== FALSE;

if (!defined(‘PHPUnit_MAIN_METHOD’))

Both comments and pings are currently closed.

Comments are closed.