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
27 * @todo this shouldn't have to be static
29 static protected $url;
34 public function __construct() {
36 * @todo this is an ugly hack to make information available to
37 * other tests. It should be fixed.
39 if ( null === self
::$_instance ) {
40 self
::$_instance = $this;
42 throw new MWException( "Already have one Selenium instance." );
46 public function start() {
47 $this->tester
= new Testing_Selenium( $this->browser
, self
::$url, $this->host
,
48 $this->port
, $this->timeout
);
49 if ( method_exists( $this->tester
, "setVerbose" ) ) $this->tester
->setVerbose( $this->verbose
);
51 $this->tester
->start();
52 $this->isStarted
= true;
55 public function stop() {
56 $this->tester
->stop();
58 $this->isStarted
= false;
61 public function login() {
62 if ( strlen( $this->user
) == 0 ) {
65 $this->open( self
::$url . '/index.php?title=Special:Userlogin' );
66 $this->type( 'wpName1', $this->user
);
67 $this->type( 'wpPassword1', $this->pass
);
68 $this->click( "//input[@id='wpLoginAttempt']" );
69 $this->waitForPageToLoad( 10000 );
71 // after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
72 $value = $this->isElementPresent( "//li[@id='pt-preferences']" );
74 if ( $value != true ) {
75 throw new Testing_Selenium_Exception( "Login Failed" );
80 public static function getInstance() {
81 if ( null === self
::$_instance ) {
82 throw new MWException( "No instance set yet" );
85 return self
::$_instance;
88 public function loadPage( $title, $action ) {
89 $this->open( self
::$url . '/index.php?title=' . $title . '&action=' . $action );
92 public function setLogger( $logger ) {
93 $this->logger
= $logger;
96 public function getLogger( ) {
100 public function log( $message ) {
101 $this->logger
->write( $message );
104 public function setUrl( $url ) {
108 static public function getUrl() {
112 public function setPort( $port ) {
116 public function getPort() {
120 public function setUser( $user ) {
124 public function setPass( $pass ) {
128 public function setHost( $host ) {
132 public function setVerbose( $verbose ) {
133 $this->verbose
= $verbose;
136 public function setAvailableBrowsers( $availableBrowsers ) {
137 $this->browsers
= $availableBrowsers;
140 public function setJUnitLogfile( $junitlogfile ) {
141 $this->junitlogfile
= $junitlogfile;
144 public function getJUnitLogfile( ) {
145 return $this->junitlogfile
;
148 public function setBrowser( $b ) {
149 if ( !isset( $this->browsers
[$b] ) ) {
150 throw new MWException( "Invalid Browser: $b.\n" );
153 $this->browser
= $this->browsers
[$b];
156 public function getAvailableBrowsers() {
157 return $this->browsers
;
160 public function __call( $name, $args ) {
161 $t = call_user_func_array( array( $this->tester
, $name ), $args );
165 // Prevent external cloning
166 protected function __clone() { }
167 // Prevent external construction
168 // protected function __construct() {}