48e505dcd52e072aa404225ad5c22e8318fed802
4 * This is implemented as a singleton.
7 require( 'Testing/Selenium.php' );
9 protected static $_instance = null;
10 public $isStarted = false;
20 protected $timeout = 30000;
24 * @todo this shouldn't have to be static
26 static protected $url;
31 public function __construct() {
33 * @todo this is an ugly hack to make information available to
34 * other tests. It should be fixed.
36 if ( null === self
::$_instance ) {
37 self
::$_instance = $this;
39 throw new MWException("Already have one Selenium instance.");
43 public function start() {
44 $this->tester
= new Testing_Selenium( $this->browser
, self
::$url, $this->host
,
45 $this->port
, $this->timeout
);
46 if ( method_exists( $this->tester
, "setVerbose" ) ) $this->tester
->setVerbose( $this->verbose
);
48 $this->tester
->start();
49 $this->isStarted
= true;
52 public function stop() {
53 $this->tester
->stop();
55 $this->isStarted
= false;
58 protected function setupBrowsers() {
60 * @todo This needs to be replaced with something not hard
61 * coded. This would be entries in a .ini file or
63 * http://grid.tesla.usability.wikimedia.org:4444/console for
67 'firefox' => 'Firefox 3.5 on Linux',
68 'iexplorer' => '*iexploreproxy',
69 'chrome' => '*googlechrome',
73 public function login() {
74 $this->open( self
::$url . '/index.php?title=Special:Userlogin' );
75 $this->type( 'wpName1', $this->user
);
76 $this->type( 'wpPassword1', $this->pass
);
77 $this->click( "//input[@id='wpLoginAttempt']" );
78 $this->waitForPageToLoad(5000);
79 //after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
80 $value = $this->isElementPresent( "//li[@id='pt-preferences']" );
81 if ( $value != true ) {
82 throw new Testing_Selenium_Exception( "Login Failed" );
87 public static function getInstance() {
88 if ( null === self
::$_instance ) {
89 throw new MWException( "No instance set yet" );
92 return self
::$_instance;
95 public function loadPage( $title, $action ) {
96 $this->open( self
::$url . '/index.php?title=' . $title . '&action=' . $action );
99 public function setLogger( $logger ) {
100 $this->logger
= $logger;
103 public function getLogger( ) {
104 return $this->logger
;
107 public function log( $message ) {
108 $this->logger
->write( $message );
111 public function setUrl( $url ) {
115 static public function getUrl() {
119 public function setPort( $port ) {
123 public function setUser( $user ) {
127 public function setPass( $pass ) {
131 public function setHost( $host ) {
135 public function setVerbose( $verbose ) {
136 $this->verbose
= $verbose;
139 public function setBrowser( $b ) {
140 $browsers = $this->setupBrowsers();
141 if ( !isset( $browsers[$b] ) ) {
142 throw new MWException( "Invalid Browser: $b.\n" );
144 $this->browser
= $browsers[$b];
147 public function __call( $name, $args ) {
148 $t = call_user_func_array( array( $this->tester
, $name), $args );
152 public function setUrl( $url ) {
156 static public function getUrl() {
160 public function setPort( $port ) {
164 public function setUser( $user ) {
168 public function setPass( $pass ) {
172 public function setHost( $host ) {
176 public function setVerbose( $verbose ) {
177 $this->verbose
= $verbose;
180 public function setBrowser( $b ) {
181 $browsers = $this->setupBrowsers();
182 if ( !isset( $browsers[$b] ) ) {
183 throw new MWException( "Invalid Browser: $b.\n" );
185 $this->browser
= $browsers[$b];
188 public function __call( $name, $args ) {
189 $t = call_user_func_array( array( $this->tester
, $name), $args );
193 // Prevent external cloning
194 protected function __clone() { }
195 // Prevent external construction
196 // protected function __construct() {}