From 7fcbb5ea7dafdcbcac2c811bce8e61bfc673bde0 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Mon, 19 Dec 2016 22:33:20 +0530 Subject: [PATCH 1/5] Fix Database create and drop selenium test Signed-off-by: Deven Bansod --- test/selenium/PmaSeleniumCreateDropDatabaseTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/selenium/PmaSeleniumCreateDropDatabaseTest.php b/test/selenium/PmaSeleniumCreateDropDatabaseTest.php index 4f4a317806..951e2ded4c 100644 --- a/test/selenium/PmaSeleniumCreateDropDatabaseTest.php +++ b/test/selenium/PmaSeleniumCreateDropDatabaseTest.php @@ -43,7 +43,7 @@ class PMA_SeleniumCreateDropDatabaseTest extends PMA_SeleniumBase $this->_dropDatabase(); - $this->waitForElement('byLinkText', "Databases")->click(); + $this->waitForElement('byPartialLinkText','Databases')->click(); $this->waitForElementNotPresent('byCssSelector', 'div#loading_parent'); $element = $this->waitForElement('byId', 'text_create_db'); @@ -52,9 +52,7 @@ class PMA_SeleniumCreateDropDatabaseTest extends PMA_SeleniumBase $this->byId("buttonGo")->click(); - $element = $this->waitForElement( - "byCssSelector", "span.ajax_notification div.success" - ); + $element = $this->waitForElement('byLinkText', 'Database: ' . $this->database_name); $this->_dropDatabase(); } @@ -68,7 +66,7 @@ class PMA_SeleniumCreateDropDatabaseTest extends PMA_SeleniumBase { $this->gotoHomepage(); - $this->byLinkText("Databases")->click(); + $this->byPartialLinkText('Databases')->click(); $this->waitForElementNotPresent('byCssSelector', 'div#loading_parent'); $this->byCssSelector( From 34bea12605e2b4604a114a8a5dd7eb0127483cbe Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Mon, 26 Dec 2016 15:45:21 +0530 Subject: [PATCH 2/5] Fix create and drop user selenium test Signed-off-by: Deven Bansod --- .../PmaSeleniumCreateRemoveUserTest.php | 24 +++++++++++++------ test/selenium/TestBase.php | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/test/selenium/PmaSeleniumCreateRemoveUserTest.php b/test/selenium/PmaSeleniumCreateRemoveUserTest.php index 629606e87a..937da32b6b 100644 --- a/test/selenium/PmaSeleniumCreateRemoveUserTest.php +++ b/test/selenium/PmaSeleniumCreateRemoveUserTest.php @@ -57,7 +57,7 @@ class PMA_SeleniumCreateRemoveUserTest extends PMA_SeleniumBase public function testCreateRemoveUser() { $this->login(); - $this->waitForElement('byLinkText', "Users")->click(); + $this->waitForElement('byPartialLinkText', "User accounts")->click(); $link = $this->waitForElement("byId", "add_user_anchor"); $link->click(); @@ -68,22 +68,32 @@ class PMA_SeleniumCreateRemoveUserTest extends PMA_SeleniumBase $select = $this->select($this->byId("select_pred_hostname")); $select->selectOptionByLabel("Local"); - $this->byId("button_generate_password")->click(); + $this->scrollIntoView('button_generate_password'); + $genButton = $this->waitForElement('byId', 'button_generate_password'); + $genButton->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(); + + // Make sure the element is visible before clicking + $this->scrollIntoView('createdb-1'); + $this->waitForElement('byId', 'createdb-1')->click(); + $this->waitForElement('byId', 'createdb-2')->click(); + + $this->scrollIntoView('addUsersForm_checkall'); $this->byId("addUsersForm_checkall")->click(); - $this->byName("adduser_submit")->click(); + + $this->waitForElement('byId', "adduser_submit")->click(); $success = $this->waitForElement("byCssSelector", "div.success"); $this->assertContains('You have added a new user', $success->text()); - $this->waitForElement('byLinkText', "Users")->click(); + // Removing the newly added user + $this->waitForElement('byPartialLinkText', "User accounts")->click(); $el = $this->waitForElement("byId", "usersForm"); $temp = $this->_txtUsername . "localhost"; @@ -93,7 +103,7 @@ class PMA_SeleniumCreateRemoveUserTest extends PMA_SeleniumBase $this->byId("checkbox_drop_users_db")->click(); $this->byId("buttonGo")->click(); - $this->waitForElement("byCssSelector", "button.confirmOK")->click(); + $this->waitForElement("byCssSelector", "button.submitOK")->click(); $this->acceptAlert(); $success = $this->waitForElement("byCssSelector", "div.success"); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 59d7976483..c6fff79c58 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -615,4 +615,28 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase "//a[@class='tabactive' and contains(., 'Browse')]" ); } + + /** + * Scrolls to a coordinate such that the element with given id is visible + * + * @param string $element_id Id of the element + * + * @return void + */ + public function scrollIntoView($element_id) + { + // 70pt offset so that the topmenu does not cover the element + $this->execute( + array( + 'script' => 'var element = document.getElementById("' + . $element_id . '");' + . 'var position = element.getBoundingClientRect();' + . 'var x = position.left;' + . 'var y = position.top;' + . 'window.scrollTo(x, y-70);', + 'args' => array() + ) + ); + usleep(10000); + } } From 65fe1c7ad64b7e517b606726e1de99d598118563 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Wed, 28 Dec 2016 23:20:02 +0530 Subject: [PATCH 3/5] Fix selenium test related to Database events Signed-off-by: Deven Bansod --- test/selenium/PmaSeleniumDbEventsTest.php | 48 +++++++++++++++-------- test/selenium/TestBase.php | 16 +++++--- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/test/selenium/PmaSeleniumDbEventsTest.php b/test/selenium/PmaSeleniumDbEventsTest.php index 16fcf220b9..335679a078 100644 --- a/test/selenium/PmaSeleniumDbEventsTest.php +++ b/test/selenium/PmaSeleniumDbEventsTest.php @@ -36,7 +36,9 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase $this->dbQuery( "INSERT INTO `test_table` (val) VALUES (2);" ); - + $this->dbQuery( + "SET GLOBAL event_scheduler=\"ON\"" + ); } /** @@ -47,13 +49,27 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase public function setUpPage() { $this->login(); - $this->waitForElement('byLinkText', $this->database_name)->click(); + $this->waitForElement('byPartialLinkText', $this->database_name)->click(); $this->waitForElement( "byXPath", "//a[contains(., 'test_table')]" ); + + // Let the Database page load + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); $this->expandMore(); } + /** + * Tear Down function for test cases + * + * @return void + */ + public function tearDown() + { + $this->dbQuery("SET GLOBAL event_scheduler=\"OFF\""); + parent::tearDown(); + } + /** * Creates procedure for tests * @@ -65,7 +81,7 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase $end = date('Y-m-d H:i:s', strtotime('+1 day')); $this->dbQuery( - "CREATE EVENT `test_event` ON SCHEDULE EVERY 2 MINUTE_SECOND STARTS " + "CREATE EVENT `test_event` ON SCHEDULE EVERY 1 MINUTE_SECOND STARTS " . "'$start' ENDS '$end' ON COMPLETION NOT PRESERVE ENABLE " . "DO UPDATE `" . $this->database_name . "`.`test_table` SET val = val + 1" @@ -84,21 +100,21 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase $ele = $this->waitForElement("byPartialLinkText", "Events"); $ele->click(); - $ele = $this->waitForElement("byLinkText", "Add event"); + $ele = $this->waitForElement("byPartialLinkText", "Add event"); $ele->click(); $this->waitForElement("byClassName", "rte_form"); - $this->byName("item_name")->value("test_event"); - $this->select($this->byName("item_type")) ->selectOptionByLabel("RECURRING"); - $this->byName("item_interval_value")->value("1"); - + $this->byName("item_name")->value("test_event"); $this->select($this->byName("item_interval_field")) ->selectOptionByLabel("MINUTE_SECOND"); + $ele = $this->waitForElement('byName', "item_interval_value"); + $ele->value('1'); + $this->byName("item_starts") ->value(date('Y-m-d H:i:s', strtotime('-1 day'))); @@ -106,7 +122,7 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase ->value(date('Y-m-d H:i:s', strtotime('+1 day'))); $proc = "UPDATE " . $this->database_name . ".`test_table` SET val=val+1"; - $this->typeInTextArea($proc); + $this->typeInTextArea($proc, 2); $this->byXPath("//button[contains(., 'Go')]")->click(); @@ -155,13 +171,13 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase "//legend[contains(., 'Events')]" ); - $this->byLinkText("Edit")->click(); + $this->byPartialLinkText("Edit")->click(); $this->waitForElement("byClassName", "rte_form"); $this->byName("item_interval_value")->clear(); - $this->byName("item_interval_value")->value("1"); - $this->typeInTextArea("00"); + $this->byName("item_interval_value")->value("2"); + $this->sleep(); $this->byXPath("//button[contains(., 'Go')]")->click(); $ele = $this->waitForElement( @@ -170,12 +186,12 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase . "'Event `test_event` has been modified')]" ); - usleep(2000000); + usleep(2200000); $result = $this->dbQuery( "SELECT val FROM `" . $this->database_name . "`.`test_table`" ); $row = $result->fetch_assoc(); - $this->assertGreaterThan(100, $row['val']); + $this->assertGreaterThan(4, $row['val']); } /** @@ -195,9 +211,9 @@ class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase "//legend[contains(., 'Events')]" ); - $this->byLinkText("Drop")->click(); + $this->byPartialLinkText("Drop")->click(); $this->waitForElement( - "byXPath", "//button[contains(., 'OK')]" + "byClassName", "submitOK" )->click(); $this->waitForElement("byId", "nothing2display"); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index c6fff79c58..0ca1608e23 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -535,11 +535,12 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase /** * Type text in textarea (CodeMirror enabled) * - * @param string $text Text to type + * @param string $text Text to type + * @param string $index Index of CodeMirror instance to write to * * @return void */ - public function typeInTextArea($text) + public function typeInTextArea($text, $index=0) { /** * Firefox needs some escaping of a text, see @@ -555,8 +556,13 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase ); } - $this->byClassName("CodeMirror-scroll")->click(); - $this->keys($text); + $this->execute( + array( + 'script' => "var cm = $('.CodeMirror')[" . $index . "].CodeMirror;" + . "cm.setValue('" . $text . "');", + 'args' => array() + ) + ); } /** @@ -574,7 +580,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase /* We need to resize to ensure it fits into accessible area */ $this->execute( array( - 'script' => "$('#topmenu').css('font-size', '50%');" + 'script' => "$('#topmenu').css('font-size', '30%');" . "$(window).resize()", 'args' => array() ) From 6bd1fe4055e8a23d71f0f96529486226d9fb1a5f Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 29 Dec 2016 15:19:56 +0530 Subject: [PATCH 4/5] Wait for notification to be not present, so that page loads completely Signed-off-by: Deven Bansod --- test/selenium/PmaSeleniumCreateRemoveUserTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/selenium/PmaSeleniumCreateRemoveUserTest.php b/test/selenium/PmaSeleniumCreateRemoveUserTest.php index 937da32b6b..8b40526a16 100644 --- a/test/selenium/PmaSeleniumCreateRemoveUserTest.php +++ b/test/selenium/PmaSeleniumCreateRemoveUserTest.php @@ -59,6 +59,9 @@ class PMA_SeleniumCreateRemoveUserTest extends PMA_SeleniumBase $this->login(); $this->waitForElement('byPartialLinkText', "User accounts")->click(); + // Let the User Accounts page load + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + $link = $this->waitForElement("byId", "add_user_anchor"); $link->click(); From d2fd27c041603697beb7f15d7b298544b32de220 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 29 Dec 2016 17:39:22 +0530 Subject: [PATCH 5/5] Fix few more errors in hover on 'More' Signed-off-by: Deven Bansod --- .../PmaSeleniumCreateDropDatabaseTest.php | 3 ++- .../selenium/PmaSeleniumCreateRemoveUserTest.php | 1 + test/selenium/TestBase.php | 16 +++++++--------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/selenium/PmaSeleniumCreateDropDatabaseTest.php b/test/selenium/PmaSeleniumCreateDropDatabaseTest.php index 951e2ded4c..e7decfa8cc 100644 --- a/test/selenium/PmaSeleniumCreateDropDatabaseTest.php +++ b/test/selenium/PmaSeleniumCreateDropDatabaseTest.php @@ -69,12 +69,13 @@ class PMA_SeleniumCreateDropDatabaseTest extends PMA_SeleniumBase $this->byPartialLinkText('Databases')->click(); $this->waitForElementNotPresent('byCssSelector', 'div#loading_parent'); + $this->scrollIntoView('tableslistcontainer'); $this->byCssSelector( "input[name='selected_dbs[]'][value='" . $this->database_name . "']" )->click(); $this->byCssSelector("button.mult_submit")->click(); - $this->byCssSelector("span.ui-button-text:nth-child(1)")->click(); + $this->byCssSelector("button.submitOK")->click(); $this->waitForElementNotPresent( "byCssSelector", diff --git a/test/selenium/PmaSeleniumCreateRemoveUserTest.php b/test/selenium/PmaSeleniumCreateRemoveUserTest.php index 8b40526a16..04df90f53e 100644 --- a/test/selenium/PmaSeleniumCreateRemoveUserTest.php +++ b/test/selenium/PmaSeleniumCreateRemoveUserTest.php @@ -62,6 +62,7 @@ class PMA_SeleniumCreateRemoveUserTest extends PMA_SeleniumBase // Let the User Accounts page load $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + $this->scrollIntoView('add_user_anchor'); $link = $this->waitForElement("byId", "add_user_anchor"); $link->click(); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 0ca1608e23..f6cfc5e37c 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -572,19 +572,17 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase */ public function expandMore() { + $ele = null; try { - $this->waitForElement('byCssSelector', 'li.submenu > a'); + $ele = $this->waitForElement('byCssSelector', 'li.submenu > a'); } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { return; } - /* We need to resize to ensure it fits into accessible area */ - $this->execute( - array( - 'script' => "$('#topmenu').css('font-size', '30%');" - . "$(window).resize()", - 'args' => array() - ) - ); + + // Will never be 'null' here + $ele->click(); + $this->waitForElement('byCssSelector', 'li.submenuhover > a'); + $this->sleep(); }