MediaWiki
REL1_21
|
00001 <?php 00007 require( 'Testing/Selenium.php' ); 00008 00009 class Selenium { 00010 protected static $_instance = null; 00011 00012 public $isStarted = false; 00013 public $tester; 00014 00015 protected $port; 00016 protected $host; 00017 protected $browser; 00018 protected $browsers; 00019 protected $logger; 00020 protected $user; 00021 protected $pass; 00022 protected $timeout = 30000; 00023 protected $verbose; 00024 protected $junitlogfile; //processed by phpUnderControl 00025 protected $runagainstgrid = false; 00026 00030 static protected $url; 00031 00035 public function __construct() { 00040 if ( null === self::$_instance ) { 00041 self::$_instance = $this; 00042 } else { 00043 throw new MWException( "Already have one Selenium instance." ); 00044 } 00045 } 00046 00047 public function start() { 00048 $this->tester = new Testing_Selenium( $this->browser, self::$url, $this->host, 00049 $this->port, $this->timeout ); 00050 if ( method_exists( $this->tester, "setVerbose" ) ) { 00051 $this->tester->setVerbose( $this->verbose ); 00052 } 00053 00054 $this->tester->start(); 00055 $this->isStarted = true; 00056 } 00057 00058 public function stop() { 00059 $this->tester->stop(); 00060 $this->tester = null; 00061 $this->isStarted = false; 00062 } 00063 00064 public function login() { 00065 if ( strlen( $this->user ) == 0 ) { 00066 return; 00067 } 00068 $this->open( self::$url . '/index.php?title=Special:Userlogin' ); 00069 $this->type( 'wpName1', $this->user ); 00070 $this->type( 'wpPassword1', $this->pass ); 00071 $this->click( "//input[@id='wpLoginAttempt']" ); 00072 $this->waitForPageToLoad( 10000 ); 00073 00074 // after login we redirect to the main page. So check whether the "Prefernces" top menu item exists 00075 $value = $this->isElementPresent( "//li[@id='pt-preferences']" ); 00076 00077 if ( $value != true ) { 00078 throw new Testing_Selenium_Exception( "Login Failed" ); 00079 } 00080 00081 } 00082 00083 public static function getInstance() { 00084 if ( null === self::$_instance ) { 00085 throw new MWException( "No instance set yet" ); 00086 } 00087 00088 return self::$_instance; 00089 } 00090 00091 public function loadPage( $title, $action ) { 00092 $this->open( self::$url . '/index.php?title=' . $title . '&action=' . $action ); 00093 } 00094 00095 public function setLogger( $logger ) { 00096 $this->logger = $logger; 00097 } 00098 00099 public function getLogger() { 00100 return $this->logger; 00101 } 00102 00103 public function log( $message ) { 00104 $this->logger->write( $message ); 00105 } 00106 00107 public function setUrl( $url ) { 00108 self::$url = $url; 00109 } 00110 00111 public static function getUrl() { 00112 return self::$url; 00113 } 00114 00115 public function setPort( $port ) { 00116 $this->port = $port; 00117 } 00118 00119 public function getPort() { 00120 return $this->port; 00121 } 00122 00123 public function setUser( $user ) { 00124 $this->user = $user; 00125 } 00126 00127 // Function to get username 00128 public function getUser() { 00129 return $this->user; 00130 } 00131 00132 00133 public function setPass( $pass ) { 00134 $this->pass = $pass; 00135 } 00136 00137 //add function to get password 00138 public function getPass() { 00139 return $this->pass; 00140 } 00141 00142 public function setHost( $host ) { 00143 $this->host = $host; 00144 } 00145 00146 public function setVerbose( $verbose ) { 00147 $this->verbose = $verbose; 00148 } 00149 00150 public function setAvailableBrowsers( $availableBrowsers ) { 00151 $this->browsers = $availableBrowsers; 00152 } 00153 00154 public function setJUnitLogfile( $junitlogfile ) { 00155 $this->junitlogfile = $junitlogfile; 00156 } 00157 00158 public function getJUnitLogfile() { 00159 return $this->junitlogfile; 00160 } 00161 00162 public function setRunAgainstGrid( $runagainstgrid ) { 00163 $this->runagainstgrid = $runagainstgrid; 00164 } 00165 00166 public function setBrowser( $b ) { 00167 if ( $this->runagainstgrid ) { 00168 $this->browser = $b; 00169 return true; 00170 } 00171 if ( !isset( $this->browsers[$b] ) ) { 00172 throw new MWException( "Invalid Browser: $b.\n" ); 00173 } 00174 00175 $this->browser = $this->browsers[$b]; 00176 } 00177 00178 public function getAvailableBrowsers() { 00179 return $this->browsers; 00180 } 00181 00182 public function __call( $name, $args ) { 00183 $t = call_user_func_array( array( $this->tester, $name ), $args ); 00184 return $t; 00185 } 00186 00187 // Prevent external cloning 00188 protected function __clone() {} 00189 // Prevent external construction 00190 // protected function __construct() {} 00191 }