require_once( dirname( dirname( __FILE__ ) )."/Maintenance.php" );
require_once( 'PHPUnit/Framework.php' );
require_once( 'PHPUnit/Extensions/SeleniumTestCase.php' );
+require_once( 'PHPUnit/Util/Log/JUnit.php' );
require_once( dirname( __FILE__ ) . "/selenium/SeleniumServerManager.php" );
-
class SeleniumTester extends Maintenance {
protected $selenium;
protected $serverManager;
$this->addOption( 'verbose', 'Be noisier.' );
$this->addOption( 'startserver', 'Start Selenium Server (on localhost) before the run.' );
$this->addOption( 'stopserver', 'Stop Selenium Server (on localhost) after the run.' );
+ $this->addOption( 'jUnitLogFile', 'Log results in a specified JUnit log file.', false, true );
$this->deleteOption( 'dbpass' );
$this->deleteOption( 'dbuser' );
$this->deleteOption( 'globals' );
protected function runTests( $seleniumTestSuites = array() ) {
$result = new PHPUnit_Framework_TestResult;
$result->addListener( new SeleniumTestListener( $this->selenium->getLogger() ) );
+ if ( $this->selenium->getJUnitLogFile() ) {
+ $jUnitListener = new PHPUnit_Util_Log_JUnit( $this->selenium->getJUnitLogFile(), true );
+ $result->addListener( $jUnitListener );
+ }
foreach ( $seleniumTestSuites as $testSuiteName => $testSuiteFile ) {
- require( $testSuiteFile );
+ require( $testSuiteFile );
$suite = new $testSuiteName();
$suite->addTests();
throw new MWException( $e->getMessage() );
}
}
+
+ if ( $this->selenium->getJUnitLogFile() ) {
+ $jUnitListener->flush();
+ }
}
public function execute() {
if ( !isset( $seleniumSettings['username'] ) ) $seleniumSettings['username'] = '';
if ( !isset( $seleniumSettings['userPassword'] ) ) $seleniumSettings['userPassword'] = '';
if ( !isset( $seleniumSettings['testBrowser'] ) ) $seleniumSettings['testBrowser'] = 'firefox';
+ if ( !isset( $seleniumSettings['jUnitLogFile'] ) ) $seleniumSettings['jUnitLogFile'] = false;
// Setup Selenium class
$this->selenium = new Selenium( );
$this->selenium->setUser( $this->getOption( 'username', $seleniumSettings['username'] ) );
$this->selenium->setPass( $this->getOption( 'userPassword', $seleniumSettings['userPassword'] ) );
$this->selenium->setVerbose( $this->hasOption( 'verbose' ) );
+ $this->selenium->setJUnitLogFile( $this->getOption( 'jUnitLogFile', $seleniumSettings['jUnitLogFile'] ) );
if( $this->hasOption( 'list-browsers' ) ) {
$this->listBrowsers();
protected $pass;
protected $timeout = 30000;
protected $verbose;
+ protected $junitlogfile; //processed by phpUnderControl
/**
* @todo this shouldn't have to be static
$this->browsers = $availableBrowsers;
}
+ public function setJUnitLogfile( $junitlogfile ) {
+ $this->junitlogfile = $junitlogfile;
+ }
+
+ public function getJUnitLogfile( ) {
+ return $this->junitlogfile;
+ }
+
public function setBrowser( $b ) {
if ( !isset( $this->browsers[$b] ) ) {
throw new MWException( "Invalid Browser: $b.\n" );