* log browser used
[lhc/web/wiklou.git] / maintenance / tests / selenium / Selenium.php
1 <?php
2 /**
3 * Selenium connector
4 * This is implemented as a singleton.
5 */
6
7 class Selenium extends Testing_Selenium {
8 protected static $_instance = null;
9 public $isStarted = false;
10
11 public static function getInstance() {
12 global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser;
13 global $wgSeleniumServerPort, $wgSeleniumLogger;
14
15 if ( null === self::$_instance ) {
16 $wgSeleniumLogger->write( "Browser: " . $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser] );
17 self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser],
18 self::getBaseUrl(),
19 $wgSeleniumTestsSeleniumHost,
20 $wgSeleniumServerPort );
21 }
22 return self::$_instance;
23 }
24
25 public function start() {
26 parent::start();
27 $this->isStarted = true;
28 }
29
30 public function stop() {
31 parent::stop();
32 $this->isStarted = false;
33 }
34
35 static function getBaseUrl() {
36 global $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
37 if ( $wgSeleniumTestsWikiUrl ) {
38 return $wgSeleniumTestsWikiUrl;
39 } else {
40 return $wgServer . $wgScriptPath;
41 }
42 }
43
44 public function login() {
45 global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword;
46
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" );
56 }
57
58 }
59
60 public function loadPage( $title, $action ) {
61 $this->open( self::getBaseUrl() . '/index.php?title=' . $title . '&action=' . $action );
62 }
63
64 /*
65 * Log to console or html depending on the value of $wgSeleniumTestsRunMode
66 */
67 public function log( $message ) {
68 global $wgSeleniumLogger;
69 $wgSeleniumLogger->write( $message );
70 }
71
72 // Prevent external cloning
73 protected function __clone() { }
74 // Prevent external construction
75 // protected function __construct() {}
76 }