Writing System Tests for Joomla! - Part 1

From Joomla! Documentation

Revision as of 15:43, 9 February 2010 by Betweenbrain (talk | contribs)
Quill icon.png
Page Actively Being Edited!

This article is actively undergoing a major edit for a short while.
As a courtesy, please do not edit this page while this message is displayed. The user who added this notice will be listed in the page history. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page. If this page has not been edited for several hours, please remove this template, or replace it with {{underconstruction}} or {{incomplete}}.

As reported at Running Automated Tests for Version 1.6, Joomla! version 1.6 now includes a library of function tests. This document details the steps necessary to create functional tests using Selenium.

NOTE: This article assumes that you have read the aforementioned article and have PHPUnit and Selenium set up and working properly.

Creating a basic functional test[edit]

A few items to note:

  • It's recommended to update your local copy of 1.6 to the latest build before writing any tests.
  • The test are written in PHP and we are using Selenium RC to execute them later. You will need to select the PHP Selenium RC Format in Slenium IDE. Go to Options -> Format -> PHP Selenium RC
  • More information about writing test can be found at http://www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html

In this test, we are going to test some of the menu items on the home page.

1. Open 1.6 in FireFox and navigate to the home page.

2. Open Selenium IDE by going to the Tools menu and select Selenium IDE. Selenium will start recording automatically and the record button will appear highligted.

3. Verify that the Base URL displayed in Selenium is that of your test site.

4. Perform the basic test by selecting the menu items to test with your mouse.

5. When you have completed your test, click the the red record button (see image below) to stop recording.

Selenium-screen.png

6. Once recording has stopped, create a new PHP file in Eclipse (or your favorite code editor) and copy / paste the code from Selenium IDE to there. The contents of the example test is:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://change-this-to-the-site-you-are-testing/");
  }

  function testMyTestCase()
  {
    $this->open("/workspace/joomla-1-6-source/index.php/using-joomla/extensions/components/search-component/search.html");
    $this->click("//div[@id='leftcolumn']/div[1]/div/div/div/ul/li[1]/a");
    $this->waitForPageToLoad("30000");
    $this->click("//div[@id='leftcolumn']/div[2]/div/div/div/ul/li[1]/a");
    $this->waitForPageToLoad("30000");
  }
}
?>


  • Since we have already set up test to work with Joomla!, and some supporting files, you can overwrite the top portion of your test with that of an existing test. For example, replace the following portion of your test:
<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://change-this-to-the-site-you-are-testing/");
  }

With the following code:

<?php

require_once 'SeleniumJoomlaTestCase.php';

/**
 * @group ControlPanel
 */
class SampleTest0001 extends SeleniumJoomlaTestCase
{

and then rename

 function testMyTestCase()

with an appropriate name, that matches the class we just named,such as

  function SampleTest0001()