4 * This is implemented as a singleton.
7 require( 'Testing/Selenium.php' );
10 protected static $_instance = null;
12 public $isStarted = false;
22 protected $timeout = 30000;
24 protected $junitlogfile; //processed by phpUnderControl
25 protected $runagainstgrid = false;
28 * @todo this shouldn't have to be static
30 static protected $url;
35 public function __construct() {
37 * @todo this is an ugly hack to make information available to
38 * other tests. It should be fixed.
40 if ( null === self
::$_instance ) {
41 self
::$_instance = $this;
43 throw new MWException( "Already have one Selenium instance." );
47 public function start() {
48 $this->tester
= new Testing_Selenium( $this->browser
, self
::$url, $this->host
,
49 $this->port
, $this->timeout
);
50 if ( method_exists( $this->tester
, "setVerbose" ) ) {
51 $this->tester
->setVerbose( $this->verbose
);
54 $this->tester
->start();
55 $this->isStarted
= true;
58 public function stop() {
59 $this->tester
->stop();
61 $this->isStarted
= false;
64 public function login() {
65 if ( strlen( $this->user
) == 0 ) {
68 $this->open( self
::$url . '/index.php?title=Special:Userlogin' );
69 $this->type( 'wpName1', $this->user
);
70 $this->type( 'wpPassword1', $this->pass
);
71 $this->click( "//input[@id='wpLoginAttempt']" );
72 $this->waitForPageToLoad( 10000 );
74 // after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
75 $value = $this->isElementPresent( "//li[@id='pt-preferences']" );
77 if ( $value != true ) {
78 throw new Testing_Selenium_Exception( "Login Failed" );
83 public static function getInstance() {
84 if ( null === self
::$_instance ) {
85 throw new MWException( "No instance set yet" );
88 return self
::$_instance;
91 public function loadPage( $title, $action ) {
92 $this->open( self
::$url . '/index.php?title=' . $title . '&action=' . $action );
95 public function setLogger( $logger ) {
96 $this->logger
= $logger;
99 public function getLogger() {
100 return $this->logger
;
103 public function log( $message ) {
104 $this->logger
->write( $message );
107 public function setUrl( $url ) {
111 public static function getUrl() {
115 public function setPort( $port ) {
119 public function getPort() {
123 public function setUser( $user ) {
127 // Function to get username
128 public function getUser() {
133 public function setPass( $pass ) {
137 //add function to get password
138 public function getPass() {
142 public function setHost( $host ) {
146 public function setVerbose( $verbose ) {
147 $this->verbose
= $verbose;
150 public function setAvailableBrowsers( $availableBrowsers ) {
151 $this->browsers
= $availableBrowsers;
154 public function setJUnitLogfile( $junitlogfile ) {
155 $this->junitlogfile
= $junitlogfile;
158 public function getJUnitLogfile() {
159 return $this->junitlogfile
;
162 public function setRunAgainstGrid( $runagainstgrid ) {
163 $this->runagainstgrid
= $runagainstgrid;
166 public function setBrowser( $b ) {
167 if ( $this->runagainstgrid
) {
171 if ( !isset( $this->browsers
[$b] ) ) {
172 throw new MWException( "Invalid Browser: $b.\n" );
175 $this->browser
= $this->browsers
[$b];
178 public function getAvailableBrowsers() {
179 return $this->browsers
;
182 public function __call( $name, $args ) {
183 $t = call_user_func_array( array( $this->tester
, $name ), $args );
187 // Prevent external cloning
188 protected function __clone() {}
189 // Prevent external construction
190 // protected function __construct() {}