Tuesday, August 9, 2011

Selenium RC + PHPUnit + Ant




1. Download the apache ant from apache site.

2. Unzip into any folder ex: C:\Ant

3. Set the system variables in sytem properties | Advanced | environmental variables
 
4. test is properly set or not in cmd prompt.  like

   c:> echo %ANT_HOME%

   It should print the correct path, if any problem then manually set the paths in the cmd prompts...

   Like,

   C:> set ANT_HOME=C:\Ant
   C:> set JAVA_HOME=C:\Program Files \Java\jre_1.6.0_03
   C:> set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;


  Now test, will properly set or not by typing,

    C:>java   --> this lists all java commands
    C:>ant   --> lists all commands
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Exmple format of preparing ant build & running
================================

1. One simple php file HomePage is written & placed @ C:/php folder.

2. Open two cmd prompts, in one run selenium-server jar & in another to run ant.

3.  Before running ant, first check phpunit runs the php file.
     C:> java -jar selenium-server.jar
     C:>php/phpunit homepage

      PHPUnit 3.5.14 by Sebastian Bergmann.
      . .
      Tests:1, Assertions:0, Errors:0


4. As per above steps, install ant & configure correctly.

5. Prepare the build.xml file & save either @ C:\>Ant or C:\php> folder

     <project name="Buzzz" default="build">
<property name="basedir" value="C:/php" />
<property name="dir.tests" value="C:/php/tests" />
<property name="dir.build" value="C:/php/build" />
<property name="dir.logs" value="C:/php/build/logs" />

 <target name="clean">
  <delete dir="${dir.build}"/>
 </target>

 <target name="prepare">
  <mkdir dir="${dir.logs}"/>
 </target>

 <target name="phpunit">
  <exec dir="${basedir}" executable="phpunit.bat" failonerror="true" >
   <arg line="--log-junit C:/php/build/logs/junit.xml HomePage" />
  </exec>
 </target>

 <target name="build" depends="clean,prepare,phpunit"/>
</project>


6. Open the cmd prompt, where now just phpunit is ran, just type ant C:\php>ant

     It builds xml & calls, phpunit & executes as below:

Failed one:
------------
Buildfile: C:\php\build.xml

clean:

prepare:
    [mkdir] Created dir: C:\php\build\logs

phpunit:
     [exec] PHPUnit 3.5.14 by Sebastian Bergmann.
     [exec]
     [exec] EE
     [exec]
     [exec] Time: 4 seconds, Memory: 3.75Mb
     [exec]
     [exec] There were 2 errors:
     [exec]
     [exec] 1) HomePage::testOpenSite
     [exec] PHPUnit_Framework_Exception: Could not connect to the Selenium RC se
rver.
     [exec]
     [exec]
     [exec] 2) HomePage::testOpenVideoSite
     [exec] PHPUnit_Framework_Exception: Could not connect to the Selenium RC se
rver.
     [exec]
     [exec]
     [exec] FAILURES!
     [exec] Tests: 2, Assertions: 0, Errors: 2.

BUILD FAILED
C:\php\build.xml:16: exec returned: 2

Total time: 4 seconds


Successone:
-------------


C:\php>ant
Buildfile: C:\php\build.xml

clean:
   [delete] Deleting directory C:\php\build

prepare:
    [mkdir] Created dir: C:\php\build\logs

phpunit:
     [exec] PHPUnit 3.5.14 by Sebastian Bergmann.
     [exec]
     [exec] .
     [exec] .
     [exec]
     [exec] Time: 01:11, Memory: 3.75Mb
     [exec]
     [exec] OK (2 tests, 2 assertions)

build:

BUILD SUCCESSFUL
Total time: 1 minute 11 seconds

7. The result looks like this in C:\php\build\lobs\junit.xml

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="HomePage" file="C:\php\HomePage.php" tests="2" assertions="2" failures="0" errors="0" time="70.402178">
    <testcase name="testOpenSite" class="HomePage" file="C:\php\HomePage.php" line="14" assertions="1" time="55.386074"/>
    <testcase name="testOpenVideoSite" class="HomePage" file="C:\php\HomePage.php" line="27" assertions="1" time="15.016104"/>
  </testsuite>
</testsuites>


Other Articles or links:


http://siwestie.wordpress.com/2010/03/22/continuous-integration-with-php-and-hudson-part-1/





No comments:

Post a Comment