Merge pull request #630 from ayushchd/selenium

Selenium 2 Compatibility
This commit is contained in:
Michal Čihař 2013-08-22 13:00:18 -07:00
commit 118905e355
6 changed files with 147 additions and 81 deletions

View File

@ -9,7 +9,7 @@
<selenium>
<browser name="Firefox on localhost"
browser="*firefox"
browser="firefox"
host="127.0.0.1"
port="4444"
timeout="30000"/>

View File

@ -89,11 +89,12 @@ class Helper
*/
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());
$this->_selenium->url($this->_config->getLoginURL());
$usernameField = $this->_selenium->byId($this->_txtUsername);
$usernameField->value($username);
$passwordField = $this->_selenium->byId($this->_txtPassword);
$passwordField->value($password);
$this->_selenium->byId($this->_btnLogin)->click();
}
/**
@ -103,7 +104,7 @@ class Helper
*/
public function isSuccessLogin()
{
if ($this->_selenium->isElementPresent("//*[@id=\"serverinfo\"]")) {
if ($this->isElementPresent("byXPath", "//*[@id=\"serverinfo\"]")) {
return true;
} else {
return false;
@ -117,7 +118,7 @@ class Helper
*/
public function isUnsuccessLogin()
{
if ($this->_selenium->isElementPresent("css=div.error")) {
if ($this->isElementPresent("byCssSelector", "div.error")) {
return true;
} else {
return false;
@ -131,8 +132,9 @@ class Helper
*/
public function gotoHomepage()
{
$this->_selenium->click("css=div#serverinfo a:contains('Server:')");
$this->_selenium->waitForElementNotPresent('css=div#loading_parent');
$e = $this->_selenium->byPartialLinkText("Server: ");
$e->click();
$this->waitForElementNotPresent('byCssSelector', 'div#loading_parent');
}
/**
@ -181,7 +183,7 @@ class Helper
*/
public function isLoggedIn()
{
return $this->_selenium->isElementPresent('//*[@id="serverinfo"]/a[1]');
return $this->isElementPresent('byXPath', '//*[@id="serverinfo"]/a[1]');
}
/**
@ -192,7 +194,7 @@ class Helper
public function logOutIfLoggedIn()
{
if ($this->isLoggedIn()) {
$this->_selenium->clickAndWait("css=img.icon.ic_s_loggoff");
$this->_selenium->byCssSelector("img.icon.ic_s_loggoff")->click();
}
}
@ -206,5 +208,42 @@ class Helper
$browserString = $this->_config->getCurrentBrowser();
return $browserString;
}
public function waitForElement($func, $arg)
{
$this->_selenium->timeouts()->implicitWait(10000);
$element = call_user_func_array(
array($this->_selenium, $func), array($arg)
);
$this->_selenium->timeouts()->implicitWait(0);
return $element;
}
public function waitForElementNotPresent($func, $arg)
{
while(true)
{
if (!$this->isElementPresent($func, $arg)) {
return true;
}
usleep(100);
}
}
public function isElementPresent($func, $arg)
{
try {
$element = call_user_func_array(
array($this->_selenium, $func), array($arg)
);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
// Element not present
return false;
}
// Element Present
return true;
}
}
?>

View File

@ -14,7 +14,7 @@ require_once 'Helper.php';
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestCase
class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_Selenium2TestCase
{
/**
* Name of database for the test
@ -38,6 +38,8 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC
public function setUp()
{
$this->_helper = new Helper($this);
// $this->setHost("http://phpMyAdmin:x2daRszTynrLnKaLAAqr@hub.browserstack.com");
// $this->setPort(8080);
$this->setBrowser($this->_helper->getBrowserString());
$this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
@ -52,12 +54,18 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC
{
$this->_dbname = 'pma_testdb' . time();
$this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD);
$this->click("link=Databases");
$this->waitForElementPresent("id=text_create_db");
$this->type("id=text_create_db", $this->_dbname);
$this->click("id=buttonGo");
$this->waitForElementPresent("css=span.ajax_notification div.success");
$this->assertElementPresent("css=span.ajax_notification div.success");
$this->byLinkText("Databases")->click();
$element = $this->_helper->waitForElement('byId', 'text_create_db');
$element->value($this->_dbname);
$this->byId("buttonGo")->click();
$element = $this->_helper->waitForElement(
"byCssSelector", "span.ajax_notification div.success"
);
$this->_dropDatabase();
}
@ -69,16 +77,23 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC
private function _dropDatabase()
{
$this->_helper->gotoHomepage();
$this->click("css=ul#topmenu a:contains('Databases')");
$this->waitForElementNotPresent('css=div#loading_parent');
$this->click(
"css=input[name='selected_dbs[]'][value='" . $this->_dbname . "']"
$this->byLinkText("Databases")->click();
$this->_helper->waitForElementNotPresent('byCssSelector', 'div#loading_parent');
$this->byCssSelector(
"input[name='selected_dbs[]'][value='" . $this->_dbname . "']"
)->click();
$this->byCssSelector("button.mult_submit")->click();
$this->byCssSelector("span.ui-button-text:nth-child(1)")->click();
$this->_helper->waitForElementNotPresent(
"byCssSelector", "input[name='selected_dbs[]'][value='" . $this->_dbname . "']"
);
$this->click("css=button.mult_submit");
$this->click("css=button:contains('OK')");
$this->waitForElementNotPresent(
"css=input[name='selected_dbs[]'][value='" . $this->_dbname . "']"
$this->_helper->waitForElement(
"byCssSelector", "span.ajax_notification div.success"
);
$this->assertElementPresent("css=span.ajax_notification div.success");
}
}

View File

@ -14,7 +14,7 @@ require_once 'Helper.php';
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
class PmaSeleniumCreateRemoveUserTest extends PHPUnit_Extensions_SeleniumTestCase
class PmaSeleniumCreateRemoveUserTest extends PHPUnit_Extensions_Selenium2TestCase
{
/**
* Username for the user
@ -61,38 +61,47 @@ class PmaSeleniumCreateRemoveUserTest extends PHPUnit_Extensions_SeleniumTestCas
public function testCreateRemoveUser()
{
$this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD);
$this->click("link=Users");
$this->waitForElementPresent("fieldset_add_user");
$this->click("link=Add user");
$this->waitForElementPresent("fieldset_add_user_login");
$this->type("name=username", $this->_txtUsername);
$this->select("id=select_pred_hostname", "label=Local");
$this->click("id=button_generate_password");
$this->assertNotEquals("", $this->getValue("text_pma_pw"));
$this->assertNotEquals("", $this->getValue("text_pma_pw2"));
$this->assertNotEquals("", $this->getValue("generated_pw"));
$this->type("id=text_pma_pw", $this->_txtPassword);
$this->type("id=text_pma_pw2", $this->_txtPassword);
$this->waitForElementPresent("fieldset_add_user_database");
$this->click("id=createdb-1");
$this->click("id=createdb-2");
$this->waitForElementPresent("fieldset_user_global_rights");
$this->click("id=addUsersForm_checkall");
$this->waitForElementPresent("fieldset_add_user_footer");
$this->click("name=adduser_submit");
$this->waitForElementPresent(
"css=div.success:contains('You have added a new user')"
);
$this->waitForElementPresent("usersForm");
$this->byLinkText("Users")->click();
$link = $this->_helper->waitForElement("byLinkText", "Add user");
$link->click();
$userField = $this->_helper->waitForElement("byName", "username");
$userField->value($this->_txtUsername);
$select = $this->select($this->byId("select_pred_hostname"));
$select->selectOptionByLabel("Local");
$this->byId("button_generate_password")->click();
$this->assertNotEquals("", $this->byId("text_pma_pw")->value());
$this->assertNotEquals("", $this->byId("text_pma_pw2")->value());
$this->assertNotEquals("", $this->byId("generated_pw")->value());
$this->byId("text_pma_pw")->value($this->_txtPassword);
$this->byId("text_pma_pw2")->value($this->_txtPassword);
$this->byId("createdb-1")->click();
$this->byId("createdb-2")->click();
$this->byId("addUsersForm_checkall")->click();
$this->byName("adduser_submit")->click();
$success = $this->_helper->waitForElement("byCssSelector", "div.success");
$this->assertContains('You have added a new user', $success->text());
$el = $this->_helper->waitForElement("byId", "usersForm");
$temp = $this->_txtUsername."&amp;#27;localhost";
$this->click(
"xpath=(//input[@name='selected_usr[]'])[@value='".$temp."']"
);
$this->click("id=checkbox_drop_users_db");
$this->getConfirmation();
$this->click("id=buttonGo");
$this->waitForElementPresent(
"css=div.success:contains('The selected users have been deleted')"
$this->byXPath(
"(//input[@name='selected_usr[]'])[@value='".$temp."']"
)->click();
$this->byId("checkbox_drop_users_db")->click();
$this->acceptAlert();
$this->byId("buttonGo")->click();
$success = $this->_helper->waitForElement("byCssSelector", "div.success");
$this->assertContains(
'The selected users have been deleted',
$success->text()
);
}
}

View File

@ -14,7 +14,7 @@ require_once 'Helper.php';
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
class PmaSeleniumLoginTest extends PHPUnit_Extensions_SeleniumTestCase
class PmaSeleniumLoginTest extends PHPUnit_Extensions_Selenium2TestCase
{
/**
* Helper Object

View File

@ -15,7 +15,7 @@ require_once 'Helper.php';
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_SeleniumTestCase
class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_Selenium2TestCase
{
/**
* Helper Object
@ -44,42 +44,45 @@ class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_SeleniumTestCase
public function testChangePassword()
{
$this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD);
$this->click("link=Change password");
$this->waitForElementPresent("id=change_password_anchor");
$this->byLinkText("Change password")->click();
$e = $this->_helper->waitForElement("byId", "change_password_anchor");
try {
$this->waitForElementPresent("id=text_pma_pw");
$this->assertEquals("", $this->getValue("text_pma_pw"));
$ele = $this->_helper->waitForElement("byId", "text_pma_pw");
$this->assertEquals("", $ele->value());
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
try {
$this->waitForElementPresent("id=text_pma_pw2");
$this->assertEquals("", $this->getValue("text_pma_pw2"));
$ele = $this->_helper->waitForElement("byId", "text_pma_pw2");
$this->assertEquals("", $ele->value());
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
try {
$this->waitForElementPresent("id=generated_pw");
$this->assertEquals("", $this->getValue("generated_pw"));
$ele = $this->_helper->waitForElement("byId", "generated_pw");
$this->assertEquals("", $ele->value());
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
$this->click("button_generate_password");
$this->assertNotEquals("", $this->getValue("text_pma_pw"));
$this->assertNotEquals("", $this->getValue("text_pma_pw2"));
$this->assertNotEquals("", $this->getValue("generated_pw"));
$this->byId("button_generate_password")->click();
$this->assertNotEquals("", $this->byId("text_pma_pw")->value());
$this->assertNotEquals("", $this->byId("text_pma_pw2")->value());
$this->assertNotEquals("", $this->byId("generated_pw")->value());
if (TESTSUITE_PASSWORD != "") {
$this->type("text_pma_pw", TESTSUITE_PASSWORD);
$this->type("text_pma_pw2", TESTSUITE_PASSWORD);
$this->click("css=button:contains('Go')");
$this->byId("text_pma_pw")->value(TESTSUITE_PASSWORD);
$this->byId("text_pma_pw2")->value(TESTSUITE_PASSWORD);
} else {
$this->click("id=nopass_1");
$this->click("css=button:contains('Go')");
$this->byId("nopass_1")->click();
}
$this->waitForElementPresent("id=result_query");
$this->assertTrue($this->isTextPresent("The profile has been updated."));
$this->byCssSelector("span.ui-button-text:nth-child(1)")->click();
$ele = $this->_helper->waitForElement("byCssSelector", "div.success");
$this->assertEquals(
"The profile has been updated.",
$ele->text()
);
}
}