4 * This is implemented as a singleton.
7 class Selenium
extends Testing_Selenium
{
8 protected static $_instance = null;
9 public $isStarted = false;
11 public static function getInstance() {
12 global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser;
13 global $wgSeleniumServerPort, $wgSeleniumLogger;
15 if ( null === self
::$_instance ) {
16 $wgSeleniumLogger->write( "Browser: " . $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser] );
17 self
::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser],
19 $wgSeleniumTestsSeleniumHost,
20 $wgSeleniumServerPort );
22 return self
::$_instance;
25 public function start() {
27 $this->isStarted
= true;
30 public function stop() {
32 $this->isStarted
= false;
35 static function getBaseUrl() {
36 global $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
37 if ( $wgSeleniumTestsWikiUrl ) {
38 return $wgSeleniumTestsWikiUrl;
40 return $wgServer . $wgScriptPath;
44 public function login() {
45 global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword;
47 $this->open( self
::getBaseUrl() . '/index.php?title=Special:Userlogin' );
48 $this->type( 'wpName1', $wgSeleniumTestsWikiUser );
49 $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword );
50 $this->click( "//input[@id='wpLoginAttempt']" );
51 $this->waitForPageToLoad(5000);
52 //after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
53 $value = $this->isElementPresent( "//li[@id='pt-preferences']" );
54 if ( $value != true ) {
55 throw new Testing_Selenium_Exception( "Login Failed" );
60 public function loadPage( $title, $action ) {
61 $this->open( self
::getBaseUrl() . '/index.php?title=' . $title . '&action=' . $action );
65 * Log to console or html depending on the value of $wgSeleniumTestsRunMode
67 public function log( $message ) {
68 global $wgSeleniumLogger;
69 $wgSeleniumLogger->write( $message );
72 // Prevent external cloning
73 protected function __clone() { }
74 // Prevent external construction
75 // protected function __construct() {}