Fixed spacing in actions/cache/filebackend/filerepo/job folder
[mediawiki.git] / tests / selenium / Selenium.php
blob07f9867125ba3446d1aa029784a2c2c98d6f2794
1 <?php
2 /**
3 * Selenium connector
4 * This is implemented as a singleton.
5 */
7 require( 'Testing/Selenium.php' );
9 class Selenium {
10 protected static $_instance = null;
12 public $isStarted = false;
13 public $tester;
15 protected $port;
16 protected $host;
17 protected $browser;
18 protected $browsers;
19 protected $logger;
20 protected $user;
21 protected $pass;
22 protected $timeout = 30000;
23 protected $verbose;
24 protected $junitlogfile; //processed by phpUnderControl
25 protected $runagainstgrid = false;
27 /**
28 * @todo this shouldn't have to be static
30 static protected $url;
32 /**
33 * Override parent
35 public function __construct() {
36 /**
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;
42 } else {
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();
60 $this->tester = null;
61 $this->isStarted = false;
64 public function login() {
65 if ( strlen( $this->user ) == 0 ) {
66 return;
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 ) {
108 self::$url = $url;
111 public static function getUrl() {
112 return self::$url;
115 public function setPort( $port ) {
116 $this->port = $port;
119 public function getPort() {
120 return $this->port;
123 public function setUser( $user ) {
124 $this->user = $user;
127 // Function to get username
128 public function getUser() {
129 return $this->user;
133 public function setPass( $pass ) {
134 $this->pass = $pass;
137 //add function to get password
138 public function getPass() {
139 return $this->pass;
142 public function setHost( $host ) {
143 $this->host = $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 ) {
168 $this->browser = $b;
169 return true;
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 );
184 return $t;
187 // Prevent external cloning
188 protected function __clone() {}
189 // Prevent external construction
190 // protected function __construct() {}