From f12182d261d26ab462326268084ca0ca6d97b46e Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Mon, 10 Jul 2017 21:44:14 +0530 Subject: [PATCH] Fix selenium tests related to ChangePassword, Login, Normalization, Serversettings Signed-off-by: Deven Bansod --- ....php => PmaSeleniumChangePasswordTest.php} | 32 ++++++++------- test/selenium/PmaSeleniumLoginTest.php | 7 +++- .../selenium/PmaSeleniumNormalizationTest.php | 7 +++- .../PmaSeleniumServerSettingsTest.php | 40 ++++++++++++++----- test/selenium/TestBase.php | 26 ++++++++++-- 5 files changed, 81 insertions(+), 31 deletions(-) rename test/selenium/{PmaSeleniumPrivilegesTest.php => PmaSeleniumChangePasswordTest.php} (59%) diff --git a/test/selenium/PmaSeleniumPrivilegesTest.php b/test/selenium/PmaSeleniumChangePasswordTest.php similarity index 59% rename from test/selenium/PmaSeleniumPrivilegesTest.php rename to test/selenium/PmaSeleniumChangePasswordTest.php index b4360e2f87..271d3662a4 100644 --- a/test/selenium/PmaSeleniumPrivilegesTest.php +++ b/test/selenium/PmaSeleniumChangePasswordTest.php @@ -1,7 +1,7 @@ login(); - $this->waitForElement('byLinkText', "Change password")->click(); $e = $this->waitForElement("byId", "change_password_anchor"); + $e->click(); + + $this->waitForElementNotPresent('byCssSelector', 'ajax_message_num_1'); + + $this->waitForElement('byXpath', "//span[contains(., 'Change password')]"); try { - $ele = $this->waitForElement("byId", "text_pma_pw"); + $ele = $this->waitForElement("byName", "pma_pw"); $this->assertEquals("", $ele->value()); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); } try { - $ele = $this->waitForElement("byId", "text_pma_pw2"); + $ele = $this->waitForElement("byName", "pma_pw2"); $this->assertEquals("", $ele->value()); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); } try { - $ele = $this->waitForElement("byId", "generated_pw"); + $ele = $this->waitForElement("byName", "generated_pw"); $this->assertEquals("", $ele->value()); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); } $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->assertNotEquals("", $this->byName("pma_pw")->value()); + $this->assertNotEquals("", $this->byName("pma_pw2")->value()); + $this->assertNotEquals("", $this->byName("generated_pw")->value()); if ($GLOBALS['TESTSUITE_PASSWORD'] != "") { - $this->byId("text_pma_pw")->clear(); - $this->byId("text_pma_pw2")->clear(); - $this->byId("text_pma_pw")->value($GLOBALS['TESTSUITE_PASSWORD']); - $this->byId("text_pma_pw2")->value($GLOBALS['TESTSUITE_PASSWORD']); + $this->byName("pma_pw")->clear(); + $this->byName("pma_pw2")->clear(); + $this->byName("pma_pw")->value($GLOBALS['TESTSUITE_PASSWORD']); + $this->byName("pma_pw2")->value($GLOBALS['TESTSUITE_PASSWORD']); } else { $this->byId("nopass_1")->click(); } - $this->byCssSelector("span.ui-button-text:nth-child(1)")->click(); + $this->byXpath("//button[contains(., 'Go')]")->click(); $ele = $this->waitForElement("byCssSelector", "div.success"); $this->assertEquals( "The profile has been updated.", diff --git a/test/selenium/PmaSeleniumLoginTest.php b/test/selenium/PmaSeleniumLoginTest.php index 268cde4067..5417d31e25 100644 --- a/test/selenium/PmaSeleniumLoginTest.php +++ b/test/selenium/PmaSeleniumLoginTest.php @@ -18,6 +18,11 @@ require_once 'TestBase.php'; */ class PMA_SeleniumLoginTest extends PMA_SeleniumBase { + public function setUpPage() + { + parent::setUpPage(); + $this->logOutIfLoggedIn(); + } /** * Test for successful login * @@ -27,7 +32,6 @@ class PMA_SeleniumLoginTest extends PMA_SeleniumBase */ public function testSuccessfulLogin() { - $this->logOutIfLoggedIn(); $this->login(); $this->waitForElement("byXPath", "//*[@id=\"serverinfo\"]"); $this->assertTrue($this->isSuccessLogin()); @@ -43,7 +47,6 @@ class PMA_SeleniumLoginTest extends PMA_SeleniumBase */ public function testLoginWithWrongPassword() { - $this->logOutIfLoggedIn(); $this->login("Admin", "Admin"); $this->waitForElement("byCssSelector", "div.error"); $this->assertTrue($this->isUnsuccessLogin()); diff --git a/test/selenium/PmaSeleniumNormalizationTest.php b/test/selenium/PmaSeleniumNormalizationTest.php index 3b7582dc0c..950d0e5450 100644 --- a/test/selenium/PmaSeleniumNormalizationTest.php +++ b/test/selenium/PmaSeleniumNormalizationTest.php @@ -43,14 +43,19 @@ class PMA_SeleniumNormalizationTest extends PMA_SeleniumBase */ public function setUpPage() { + parent::setUpPage(); + $this->login(); $this->navigateTable('test_table'); $this->waitForElement( "byXPath", "(//a[contains(., 'Structure')])" )->click(); + + $this->waitForElementNotPresent('byCssSelector', 'div#loading_parent'); + $this->waitForElement("byId", "tablestructure"); - $this->byLinkText('Improve table structure')->click(); + $this->byPartialLinkText('Normalize')->click(); $this->waitForElement("byId", "normalizeTable"); } diff --git a/test/selenium/PmaSeleniumServerSettingsTest.php b/test/selenium/PmaSeleniumServerSettingsTest.php index 016e292d88..cdf86b2ad7 100644 --- a/test/selenium/PmaSeleniumServerSettingsTest.php +++ b/test/selenium/PmaSeleniumServerSettingsTest.php @@ -25,9 +25,13 @@ class PMA_SeleniumSettingsTest extends PMA_SeleniumBase */ public function setUpPage() { + parent::setUpPage(); + $this->login(); $this->expandMore(); - $this->waitForElement("byLinkText", "Settings")->click(); + $this->waitForElement("byPartialLinkText", "Settings")->click(); + $this->waitForElementNotPresent('byCssSelector', 'ajax_message_num_1'); + $this->waitForElement( "byXPath", "//a[@class='tabactive' and contains(., 'Settings')]" ); @@ -41,8 +45,16 @@ class PMA_SeleniumSettingsTest extends PMA_SeleniumBase */ private function _saveConfig() { - $this->byName("submit_save")->click(); - $this->sleep(); + // Submit the form + $ele = $this->waitForElement( + 'byXPath', + "//fieldset[not(contains(@style,'display: none;'))]//input[@value='Apply']" + ); + $this->scrollToBottom(); + $this->moveto($ele); + $ele->click(); + + usleep(1000000); $this->waitForElement( "byXPath", "//div[@class='success' and contains(., 'Configuration has been saved')]" @@ -58,13 +70,15 @@ class PMA_SeleniumSettingsTest extends PMA_SeleniumBase */ public function testHideDatabase() { - /* FIXME: This test fails even though it is same as testHideLogo */ - $this->markTestIncomplete('Currently broken'); + $this->byPartialLinkText("Features")->click(); + $this->waitForElementNotPresent('byCssSelector', 'ajax_message_num_1'); - $this->byLinkText("Features")->click(); + $this->waitForElement('byXPath', "//a[contains(@href, '#Databases')]")->click(); + + $ele = $this->waitForElement("byName", "Servers-1-hide_db"); + $this->moveto($ele); + $ele->value($this->database_name); - $this->waitForElement("byName", "Servers-1-hide_db") - ->value($this->database_name); $this->_saveConfig(); $this->assertFalse( $this->isElementPresent("byLinkText", $this->database_name) @@ -86,10 +100,12 @@ class PMA_SeleniumSettingsTest extends PMA_SeleniumBase */ public function testSettingsTabsAreDisplayed() { - $this->byLinkText("SQL queries")->click(); + $this->byPartialLinkText("SQL queries")->click(); + $this->waitForElementNotPresent('byCssSelector', 'ajax_message_num_1'); + $this->waitForElement('byClassName', 'tabs'); - $this->byLinkText("SQL Query box")->click(); + $this->byPartialLinkText("SQL Query box")->click(); $this->assertTrue( $this->byId("Sql_box")->displayed() ); @@ -115,7 +131,8 @@ class PMA_SeleniumSettingsTest extends PMA_SeleniumBase */ public function testHideLogo() { - $this->byLinkText("Navigation panel")->click(); + $this->byPartialLinkText("Navigation panel")->click(); + $this->waitForElementNotPresent('byCssSelector', 'ajax_message_num_1'); $this->waitForElement("byName", "NavigationDisplayLogo") ->click(); @@ -126,6 +143,7 @@ class PMA_SeleniumSettingsTest extends PMA_SeleniumBase $this->byCssSelector("a[href='#NavigationDisplayLogo']")->click(); $this->_saveConfig(); + $this->sleep(); $this->assertTrue( $this->isElementPresent("byId", "imgpmalogo") ); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 85c121a1e7..b52e1617f8 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -593,8 +593,12 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase */ public function navigateTable($table) { - // go to database page - $this->waitForElement("byLinkText", $this->database_name)->click(); + // Go to server databases + $this->waitForElement('byPartialLinkText','Databases')->click(); + $this->waitForElementNotPresent('byCssSelector', 'div#loading_parent'); + + // go to specific database page + $this->waitForElement("byPartialLinkText", $this->database_name)->click(); /* Wait for loading and expanding tree */ $this->waitForElement( @@ -608,7 +612,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase // go to table page $this->waitForElement( "byXPath", - "//*[@id='pma_navigation_tree_content']//a[contains(., '$table')]" + "//th//a[contains(., '$table')]" )->click(); // Wait for it to load @@ -641,4 +645,20 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase ); usleep(10000); } + + /** + * Scroll to the bottom of page + * + * @return void + */ + public function scrollToBottom() + { + $this->execute( + array( + 'script' => 'window.scrollTo(0,document.body.scrollHeight);', + 'args' => array() + ) + ); + usleep(10000); + } }