7db805a1024272f850affe506b11c39c07d89183
[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;
14 if ( null === self::$_instance ) {
15 self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser],
16 self::getBaseUrl(),
17 $wgSeleniumTestsSeleniumHost,
18 $wgSeleniumServerPort );
19 }
20 return self::$_instance;
21 }
22
23 public function start() {
24 global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost;
25 parent::start();
26 $this->isStarted = true;
27 }
28
29 public function stop() {
30 parent::stop();
31 $this->isStarted = false;
32 }
33
34 static function getBaseUrl() {
35 global $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
36 if ( $wgSeleniumTestsWikiUrl ) {
37 return $wgSeleniumTestsWikiUrl;
38 } else {
39 return $wgServer . $wgScriptPath;
40 }
41 }
42
43 public function login() {
44 global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword;
45
46 $this->open( self::getBaseUrl() . '/index.php?title=Special:Userlogin' );
47 $this->type( 'wpName1', $wgSeleniumTestsWikiUser );
48 $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword );
49 $this->click( "//input[@id='wpLoginAttempt']" );
50 $value = $this->doCommand( 'assertTitle', array( 'Login successful*' ) );
51 }
52
53 public function loadPage( $title, $action ) {
54 $this->open( self::getBaseUrl() . '/index.php?title=' . $title . '&action=' . $action );
55 }
56
57 // Prevent external cloning
58 protected function __clone() { }
59 // Prevent external construction
60 // protected function __construct() {}
61 }