Skip to content

Commit

Permalink
Make selenium tests full dynamics, no more build_tests.php required.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Dec 29, 2011
1 parent 8e88f39 commit 3c0c7c0
Show file tree
Hide file tree
Showing 19 changed files with 1,261 additions and 1,239 deletions.
2 changes: 0 additions & 2 deletions .gitignore
@@ -1,4 +1,2 @@
selenium/tests/config.inc.php
tests/selenium/config.test.php
tests/selenium/TestSuite.html
tests/selenium/static
107 changes: 0 additions & 107 deletions build_tests.php

This file was deleted.

2 changes: 1 addition & 1 deletion intro.php
Expand Up @@ -62,7 +62,7 @@
<li><a href="<?php echo $lang['strpgsqlhome_url'] ?>"><?php echo $lang['strpgsqlhome'] ?></a></li>
<li><a href="http://sourceforge.net/tracker/?group_id=37132&amp;atid=418980"><?php echo $lang['strreportbug'] ?></a></li>
<li><a href="<?php echo $lang['strviewfaq_url'] ?>"><?php echo $lang['strviewfaq'] ?></a></li>
<li><a target="_top" href="tests/selenium/selenium-lib/core/TestRunner.html?test=..%2F..%2Fstatic%2FTestSuite.html&resultsUrl=..%2FpostResults">Selenium tests</a></li>
<li><a target="_top" href="tests/selenium/selenium-lib/core/TestRunner.html?test=..%2F..%2FTestSuite.php&resultsUrl=..%2FpostResults">Selenium tests</a></li>
</ul>

<?php
Expand Down
3 changes: 2 additions & 1 deletion libraries/errorhandler.inc.php
Expand Up @@ -6,7 +6,8 @@
* $Id: errorhandler.inc.php,v 1.20 2005/11/13 08:39:49 chriskl Exp $
*/

define('ADODB_ERROR_HANDLER','Error_Handler');
if (! defined('ADODB_ERROR_HANDLER'))
define('ADODB_ERROR_HANDLER','Error_Handler');

/**
* Default Error Handler. This will be called with the following params
Expand Down
49 changes: 19 additions & 30 deletions tests/selenium/README
@@ -1,58 +1,47 @@
HowTo run the tests follow these steps :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HowTo run the tests
~~~~~~~~~~~~~~~~~~~

1. Create & configure your ./tests/selenium/config.test.php (See sample one in ./tests/selenium/config.inc.php-dist).
2. Run the ./build_tests.php script
This script builds the TestSuite.html file and all the related html tests files in ./tests/selenium/static/.
It builds one directory for each server selected to run the tests in your ./tests/selenium/config.inc.php
and creates the static selenium html test files for each of them.
3. Open your browser and go to http://$webUrl/
Where $webUrl is the value set in your ./tests/selenium/config.inc.php
4. Click on "Selenium tests" on the PPA intro page & run the tests using the "Selenium TestRunner" buttons in the top-right frame.
2. Open your browser and go to http://$webUrl/
Where $webUrl is the value set in your ./tests/selenium/config.inc.php
3. Click on "Selenium tests" on the PPA intro page & run the tests using the "Selenium TestRunner" buttons in the top-right frame.

Enjoy the tests.


HowTo write new tests:
HowTo write new tests
~~~~~~~~~~~~~~~~~~~~~
The selenium's HTML tests files cannot behave differently in regard to the PG backend where the tests are run on. In order to address
this issue we are using "test-builder" scripts to create these static HTML files. These scripts are connected to each backends using
the PPA database classes and allow you to use their methods, and especialy the $data->has*() ones, throught the $data variable like
in any other ppa script.

1. how build_tests is working and why
The build_tests.php script is processing the test-builders scripts from ./tests/selenium/src in alphanumeric order. That's why each
Normaly, the selenium's statis HTML tests files cannot behave differently in regard to the PG backend where the tests are run on. In order to address
this issue we are using PHP scripts that connect to each backends using the PPA database classes and allow you to use their methods,
and especialy the $data->has*() ones, throught the $data variable like in any other ppa script.

TestSuite.php is the test suite script that build the list of tests groups (top left frame).

1. how TestSuite.php is working and why
TestSuite.php script is processing the test-builders scripts from ./tests/selenium/src in alphanumeric order. That's why each
test-builder's name should follow these rules: begin with 2numeric number, then -, then the script name (ex. 01-test1.php or 46-test46.php).

It allows to enforce the order the scripts will be run during the testSuite. This way, column's tests could be run *after* the table's tests
in the test suite and use the previous created tables.

2. how test-builder are working

These scripts are included and executed in the build_tests.php in alphanumeric order.
They should:
- begin with the declaration of the global values $testsuite_file and $test_static_dir which holds the paths to the TestSuite file
and the static folder where the HTML tests files are created
These scripts are included and executed in TestSuite.php in alphanumeric order. See comments in file ./tests/selenium/src/skeleton.php-dist
which is a template of test-builder.
When executed from TestSuite.php, test-builders should:
- create a "TestBuilder" intance which gonna helps write HTML tests quickly.
The constructor takes the following arguments:
- server's label (from your config.inc.php)
- HTML title of the page
- Test description (appears on top of the tests table)

$t = new TestBuilder($server['desc'],
'Index tests',
$t = new TestBuilder('Index tests',
'Create/Drop an unique Index'
);

- once the TestBuilder instance is created, you can use it to write our tests.
- In particular, you should use the login($username, $pass) and logout() methods to create appropriate steps to login/logout to the current
- You should use the login($username, $pass) and logout() methods to create appropriate steps to login/logout to the current
server.
- Each selenium actions are mapped (or should be) as methods. As instance, if you want to use the clickAndWait action, you should call the
clickAndWait($locator) method. For the assertText, assertText($selector, $value), etc...
- Use the addComment method to show comments anywhere in the tests page. Usefull to explain whatthe next tests are going to do.

- finish whith calling the TestBuilder's "writeTests" method which will create the selenium HTML test file in the static dir and append this
new test file to the testSuite file.

$t->writeTests("{$test_static_dir}/{$server['desc']}/view.html", $testsuite_file);

52 changes: 52 additions & 0 deletions tests/selenium/TestSuite.php
@@ -0,0 +1,52 @@
<?php
/**
* Build the test files for each servers in config.test.php
*/

chdir('../..'); /* go back to root so we can include scripts */

function oops($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) {
echo "</table><div>{$errmsg}</div>\n";
exit;
}

$_no_db_connection = true; /* load lib.inc.php without trying to connect */

require_once('./libraries/lib.inc.php');
require('./tests/selenium/config.test.php');
require_once('./classes/database/Connection.php');

$test_dir = './tests/selenium';
$test_src_dir = "{$test_dir}/src";

echo "<table border=\"1\">
<tr>
<th>Test suite for PPA</th>
</tr>\n";

$servers = $misc->getServers();

/* Loop on the servers given in the conf/config.inc.conf file */
foreach ($servers as $server) {
// Is this server in our list of configured servers?
if (!in_array($server['desc'], $test_servers))
continue;

$fd = opendir($test_src_dir);
$files = array();
while ($file = readdir($fd))
if (preg_match('@[0-9]+.*\.php$@', $file))
$files[] = $file;
closedir($fd);
sort($files);
/* include the tests creator scripts here
* in the order you want them executed.
* Each script append itself to the TestSuite.html file.
**/
foreach ($files as $testgroupfile) {
require("{$test_src_dir}/{$testgroupfile}");
echo "<tr><td><a href=\"{$webUrl}/{$test_src_dir}/{$testgroupfile}?server={$server['id']}&amp;run=1\">[{$server['desc']}] {$test_title}</a></td></tr>\n";
}
}
echo "</table>";
?>

0 comments on commit 3c0c7c0

Please sign in to comment.