How to install PHP, Apache, MySQL on Ubuntu in two commands

Installing LAMP stack on Ubuntu 10.04 and above involves having access to terminal window and root user.

First install tasksel which is used to execute tasks on system like installation of LAMP.

1. To install tasksel, execute the following command-

sudo apt-get install tasksel

2. Now install PHP, Apache, MySQL

sudo tasksel install lamp-server

Done. Now open a browser window and type “http://locahost”. You will see a message “It Work’s”.

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-

http://www.unclecode.com/2010/05/install-phpunit-on-wamp-xamp-manually-without-pear/

http://www.unclecode.com/2012/05/how-to-setup-selenium-webdriver-and-execute-automation-script/

http://www.unclecode.com/2012/06/executing-and-creating-selenium-rc-automation-test-cases-using-phpunit-by-sebastian-bergmann/

Install Ant

Download ant from http://ant.apache.org/bindownload.cgi “zip” file for windows.
Follow all the steps for installation http://ant.apache.org/manual/install.html 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.

build.xml

<!– 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” />
</condition>

<tstamp/>

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

<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>

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

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

<target name=”phpunit”>
<!– Check if folder empty –>
<fileset id=”fileset.test” dir=”${testFolder}”>
<include name=”*.*”/>
</fileset>
<fail message=”Files not found”>
<condition>
<resourcecount refid=”fileset.test” when=”less” count=”1″></resourcecount>
</condition>
</fail>
<!– 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” />
</exec>
</target>

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

AllMyTests.php file under “runtest” folder

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

spl_autoload_register(“autoloader_for_tests”);

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

class AllMyTests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}

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

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

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

foreach($files as $file_name)
{
include_once($file_name);

$phpunitsuitName = str_replace(PATTERN_OF_TEST_FILES, ”, $file_name);
$phpunitsuit->addTestSuite($phpunitsuitName);
}
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’))
{
AllMyTests::main();
}
?>

Executing and Creating Selenium RC automation test cases using PHPUnit (by Sebastian Bergmann)

  1. Setup PHPUnit framework http://www.unclecode.com/2010/05/install-phpunit-on-wamp-xamp-manually-without-pear/ assuming PHP 5.2.x is already installed in your system. If not download wamp to install PHP or browse php.net download section to install PHP.
  2. Make sure your PHP path is set in your environment so that you can execute PHP through command prompt. For reference check step 3 and 4 of article http://www.unclecode.com/2010/05/install-phpunit-on-wamp-xamp-manually-without-pear/Download and install latest Java JRE (if does not exist on your system).
  3. Download Selenium server and start the server through following command on command prompt http://seleniumhq.org/download/
  4. The above steps are explained in http://www.unclecode.com/2012/05/how-to-setup-selenium-webdriver-and-execute-automation-script/
  5. Download and Install latest firefox
  6. Install Firefox Selenium IDE plugin http://seleniumhq.org/download/ under section Selenium IDE “Download version 1.8.0 released on 24/April/2012”
  7. Install Selenium PHP plugin to generate/export scripts of type PHPUnit framework https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-php-formatters/
  8. Record script through Selenium IDE plugin
  9. Save the test suit and Export test case to PHPUnit framework through Selenium IDE export option under File menu
  10. Open command line and make sure phpunit is working by executing command “phpunit –version”
  11. Open the file which you have exported above in a editor and include the following line-
  12. require_once(‘PHPUnit/Extensions/SeleniumTestCase.php’);
  13. The name of the file (like PhpUnitSelenium.php) and class name should be same i.e. like-
    class PhpUnitSelenium extends PHPUnit_Extensions_SeleniumTestCase
  14. Make sure your selenium running in a command prompt
  15. Now open another command prompt and browse to the directory where you have saved the exported test case file and execute the following command like-
    C:\wamp\www\php-selenium-webdriver\tests>phpunit PhpUnitSelenium
  16. The above should open a new selenium firefox window to execute tests