* WebStart.php and SeleniumWebSettings.php allow include files and global config variables to be set based on the testsuite being run. See discussion in http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration

* Let test suites run without logging in.
This commit is contained in:
Priyanka Dhanda 2010-10-14 16:38:40 +00:00
parent 9ad58598da
commit cb57d56d8b
6 changed files with 109 additions and 18 deletions

View file

@ -0,0 +1,69 @@
<?php
/*
* Dynamically change configuration variables based on the test suite name and a cookie value.
* For details on how to configure a wiki for a Selenium test, see:
* http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration
*/
if ( !$wgEnableSelenium ) {
return;
}
$cookiePrefix = $wgSitename . "-";
$name = $cookiePrefix . "Selenium";
//if we find a request parameter containing the test name, set a cookie with the test name
if ( array_key_exists( 'setupTestSuite', $_GET) ) {
//TODO: do a check for valid testsuite names
$setupTestSuiteName = $_GET['setupTestSuite'];
if ( strlen( $setupTestSuiteName) > 0 ) {
$expire = time() + 600;
setcookie( $name,
$setupTestSuiteName,
$expire,
$wgCookiePath,
$wgCookieDomain,
$wgCookieSecure,
true );
}
}
//clear the cookie based on a request param
if ( array_key_exists( 'clearTestSuite', $_GET) ) {
$expire = time() - 600;
setcookie( $name,
'',
$expire,
$wgCookiePath,
$wgCookieDomain,
$wgCookieSecure,
true );
}
//if a cookie is found, run the appropriate callback to get the config params.
if ( array_key_exists( $name, $_COOKIE) ) {
$testSuiteName = $_COOKIE[$name];
$testIncludes = array(); //array containing all the includes needed for this test
$testGlobalConfigs = array(); //an array containg all the global configs needed for this test
if ( isset( $wgSeleniumTestConfigs ) && array_key_exists($testSuiteName, $wgSeleniumTestConfigs) ) {
$callback = $wgSeleniumTestConfigs[$testSuiteName];
call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs));
}
foreach ( $testIncludes as $includeFile ) {
$file = $IP . '/' . $includeFile;
require_once( $file );
}
foreach ( $testGlobalConfigs as $key => $value ) {
if ( is_array( $value ) ) {
$configArray = array();
if ( isset( $GLOBALS[$key] ) ) {
$configArray = $GLOBALS[$key];
}
foreach ( $value as $configKey => $configValue ) {
$configArray[$configKey] = $configValue;
}
$GLOBALS[$key] = $configArray;
} else {
$GLOBALS[$key] = $value;
}
}
}

View file

@ -114,6 +114,11 @@ if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
# Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
require_once( "$IP/LocalSettings.php" );
}
if ( $wgEnableSelenium ) {
require_once( "$IP/includes/SeleniumWebSettings.php" );
}
wfProfileOut( 'WebStart.php-conf' );
wfProfileIn( 'WebStart.php-ob_start' );
@ -135,3 +140,4 @@ wfProfileOut( 'WebStart.php-ob_start' );
if ( !defined( 'MW_NO_SETUP' ) ) {
require_once( "$IP/includes/Setup.php" );
}

View file

@ -120,6 +120,7 @@ class SeleniumTester extends Maintenance {
foreach ( $seleniumTestSuites as $testSuiteName => $testSuiteFile ) {
require( $testSuiteFile );
$suite = new $testSuiteName();
$suite->setName( $testSuiteName );
$suite->addTests();
try {

View file

@ -3,6 +3,7 @@
abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite {
private $selenium;
private $isSetUp = false;
private $loginBeforeTests = true;
// Do not add line break after test output
const CONTINUE_LINE = 1;
@ -20,12 +21,14 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite {
$this->isSetUp = true;
$this->selenium = Selenium::getInstance();
$this->selenium->start();
//$this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() );
$this->login();
$this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() );
if ( $this->loginBeforeTests ) {
$this->login();
}
}
public function tearDown() {
//$this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() );
$this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() );
$this->selenium->stop();
}
@ -36,4 +39,8 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite {
public function loadPage( $title, $action ) {
$this->selenium->loadPage( $title, $action );
}
protected function setLoginBeforeTests( $loginBeforeTests = true ) {
$this->loginBeforeTests = $loginBeforeTests;
}
}

View file

@ -1,9 +1,10 @@
<?php
class SimpleSeleniumTestCase extends SeleniumTestCase
{
public function testBasic()
{
/*
* This test case is part of the SimpleSeleniumTestSuite.
* Configuration for these tests are dosumented as part of SimpleSeleniumTestSuite.php
*/
class SimpleSeleniumTestCase extends SeleniumTestCase {
public function testBasic() {
$this->open( $this->getUrl() .
'/index.php?title=Selenium&action=edit' );
$this->type( "wpTextbox1", "This is a basic test" );
@ -14,19 +15,12 @@ class SimpleSeleniumTestCase extends SeleniumTestCase
$source = $this->getText( "//div[@id='wikiPreview']/p" );
$correct = strstr( $source, "This is a basic test" );
$this->assertEquals( $correct, true );
}
/*
* Needs the following in your LocalConfig or an alternative method of configuration (coming soon)
* require_once( "$IP/extensions/UsabilityInitiative/Vector/Vector.php" );
* $wgDefaultSkin='vector';
*/
public function testGlobalVariable1()
{
public function testGlobalVariableForDefaultSkin() {
$this->open( $this->getUrl() . '/index.php?&action=purge' );
$bodyClass = $this->getAttribute( "//body/@class" );
$this-> assertContains('skin-vector', $bodyClass, 'Vector skin not set');
$this-> assertContains('skin-chick', $bodyClass, 'Chick skin not set');
}
}

View file

@ -1,7 +1,21 @@
<?php
/*
* Sample test suite.
* Two ways to configure MW for these tests
* 1) If you are running multiple test suites, add the following in LocalSettings.php
* require_once("maintenance/tests/selenium/SimpleSeleniumConfig.php");
* $wgSeleniumTestConfigs['SimpleSeleniumTestSuite'] = 'SimpleSeleniumConfig::getSettings';
* OR
* 2) Add the following to your Localsettings.php
* require_once( "$IP/skins/Chick.php" );
* $wgDefaultSkin = 'chick';
*/
class SimpleSeleniumTestSuite extends SeleniumTestSuite
{
public function setUp() {
$this->setLoginBeforeTests( false );
parent::setUp();
}
public function addTests() {
$testFiles = array(
'maintenance/tests/selenium/SimpleSeleniumTestCase.php'