_txtUsername = 'input_username'; $this->_txtPassword = 'input_password'; $this->_btnLogin = 'input_go'; $this->_config = new TestConfig(); $this->_selenium = $selenium; $this->_mysqli = null; } /** * perform a login * * @param string $username Username * @param string $password Password * * @return void */ public function login($username, $password) { $this->_selenium->open($this->_config->getLoginURL()); $this->_selenium->type($this->_txtUsername, $username); $this->_selenium->type($this->_txtPassword, $password); $this->_selenium->clickAndWait($this->_btnLogin); //$this->_selenium->waitForPageToLoad($this->_config->getTimeoutValue()); } /** * Checks whether the login is successful * * @return boolean */ public function isSuccessLogin() { if ($this->_selenium->isElementPresent("//*[@id=\"serverinfo\"]")) { return true; } else { return false; } } /** * Checks whether the login is unsuccessful * * @return boolean */ public function isUnsuccessLogin() { if ($this->_selenium->isElementPresent("css=div.error")) { return true; } else { return false; } } /** * Used to go to the homepage * * @return void */ public function gotoHomepage() { $this->_selenium->click("css=div#serverinfo a:contains('Server:')"); $this->_selenium->waitForElementNotPresent('css=div#loading_parent'); } /** * Establishes a connection with the local database * * @return void */ public function dbConnect() { if ($this->_mysqli === null) { list($user, $pass) = $this->_config->getDBCredentials(); $this->_mysqli = new mysqli( "localhost", $user, $pass ); if ($this->_mysqli->connect_errno) { throw new Exception( 'Failed to connect to MySQL (' . $this->_mysqli->error . ')' ); } } } /** * Executes a database query * * @param string $query SQL Query to be executed * * @return void */ public function dbQuery($query) { if ($this->_mysqli === null) { throw new Exception( 'MySQL not connected' ); } $this->_mysqli->query($query); } } ?>