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" ) ) $this->tester->setVerbose( $this->verbose );
52 $this->tester->start();
53 $this->isStarted = true;
56 public function stop() {
57 $this->tester->stop();
59 $this->isStarted = false;
62 public function login() {
63 if ( strlen( $this->user ) == 0 ) {
66 $this->open( self::$url . '/index.php?title=Special:Userlogin' );
67 $this->type( 'wpName1', $this->user );
68 $this->type( 'wpPassword1', $this->pass );
69 $this->click( "//input[@id='wpLoginAttempt']" );
70 $this->waitForPageToLoad( 10000 );
72 // after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
73 $value = $this->isElementPresent( "//li[@id='pt-preferences']" );
75 if ( $value != true ) {
76 throw new Testing_Selenium_Exception( "Login Failed" );
81 public static function getInstance() {
82 if ( null === self::$_instance ) {
83 throw new MWException( "No instance set yet" );
86 return self::$_instance;
89 public function loadPage( $title, $action ) {
90 $this->open( self::$url . '/index.php?title=' . $title . '&action=' . $action );
93 public function setLogger( $logger ) {
94 $this->logger = $logger;
97 public function getLogger( ) {
101 public function log( $message ) {
102 $this->logger->write( $message );
105 public function setUrl( $url ) {
109 static public function getUrl() {
113 public function setPort( $port ) {
117 public function getPort() {
121 public function setUser( $user ) {
125 // Function to get username
126 public function getUser() {
131 public function setPass( $pass ) {
135 //add function to get password
136 public function getPass( ) {
141 public function setHost( $host ) {
145 public function setVerbose( $verbose ) {
146 $this->verbose = $verbose;
149 public function setAvailableBrowsers( $availableBrowsers ) {
150 $this->browsers = $availableBrowsers;
153 public function setJUnitLogfile( $junitlogfile ) {
154 $this->junitlogfile = $junitlogfile;
157 public function getJUnitLogfile( ) {
158 return $this->junitlogfile;
161 public function setRunAgainstGrid( $runagainstgrid ) {
162 $this->runagainstgrid = $runagainstgrid;
165 public function setBrowser( $b ) {
166 if ($this->runagainstgrid) {
170 if ( !isset( $this->browsers[$b] ) ) {
171 throw new MWException( "Invalid Browser: $b.\n" );
174 $this->browser = $this->browsers[$b];
177 public function getAvailableBrowsers() {
178 return $this->browsers;
181 public function __call( $name, $args ) {
182 $t = call_user_func_array( array( $this->tester, $name ), $args );
186 // Prevent external cloning
187 protected function __clone() { }
188 // Prevent external construction
189 // protected function __construct() {}