From 58be76e4e77757e76c686e07d2e1e175347f227b Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Tue, 15 Aug 2017 16:10:37 +0530 Subject: [PATCH 1/2] Add selenium tests for Query-by-example Signed-off-by: Deven Bansod --- .../PmaSeleniumQueryByExampleTest.php | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 test/selenium/PmaSeleniumQueryByExampleTest.php diff --git a/test/selenium/PmaSeleniumQueryByExampleTest.php b/test/selenium/PmaSeleniumQueryByExampleTest.php new file mode 100644 index 0000000000..ca03efc669 --- /dev/null +++ b/test/selenium/PmaSeleniumQueryByExampleTest.php @@ -0,0 +1,204 @@ +dbQuery( + "CREATE TABLE `test_table` (" + . " `id` int(11) NOT NULL AUTO_INCREMENT," + . " `val` int(11) NOT NULL," + . " PRIMARY KEY (`id`)" + . ")" + ); + $this->dbQuery( + "INSERT INTO `test_table` (val) VALUES (2), (6), (5), (3), (4), (4), (5);" + ); + } + + /** + * setUp function that can use the selenium session (called before each test) + * + * @return void + */ + public function setUpPage() + { + parent::setUpPage(); + + $this->login(); + } + + /** + * Test typing a SQL query on Server SQL page and submitting it + * + * @return void + */ + public function testQueryByExample() + { + // 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( + 'byCssSelector', + 'li.last.table' + ); + + $this->waitForElement('byPartialLinkText', 'Query')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + /* Select Columns to be used in the query */ + $select = $this->select( + $this->waitForElement('byName', 'criteriaColumn[0]') + ); + $select->selectOptionByLabel('`test_table`.`id`'); + + $select = $this->select( + $this->waitForElement('byName', 'criteriaColumn[1]') + ); + $select->selectOptionByLabel('`test_table`.`val`'); + + /* Set aliases for the columns */ + $this->waitForElement('byName', 'criteriaAlias[0]')->value('ID'); + $this->waitForElement('byName', 'criteriaAlias[1]')->value('VAL'); + + /* Set Sort orders */ + $select = $this->select( + $this->waitForElement('byName', 'criteriaSort[0]') + ); + $select->selectOptionByLabel('Descending'); + + $select = $this->select( + $this->waitForElement('byName', 'criteriaSort[1]') + ); + $select->selectOptionByLabel('Ascending'); + + /* Select sort order amongst columns */ + $select = $this->select( + $this->waitForElement('byName', 'criteriaSortOrder[0]') + ); + $select->selectOptionByLabel('2'); + + $select = $this->select( + $this->waitForElement('byName', 'criteriaSortOrder[1]') + ); + $select->selectOptionByLabel('1'); + + /* Set criteria conditions */ + $this->waitForElement('byName', 'criteria[0]')->value('> 1'); + $this->waitForElement('byName', 'criteria[1]')->value('< 6'); + + /* Change operator to AND */ + $radioElements = $this->elements( + $this->using('css selector')->value('input[name="criteriaAndOrColumn[0]"]') + ); + if (count($radioElements) > 2) { + $radioElements[1]->click(); + } + + $this->scrollToBottom(); + + /* Update Query in the editor */ + $this->byCssSelector('input[name=modify]')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + $this->scrollToBottom(); + sleep(1); + + $expected = "SELECT `test_table`.`id` AS `ID`, `test_table`.`val` AS `VAL`" + . "\nFROM `test_table`" + . "\nWHERE ((`test_table`.`id` > 1) AND (`test_table`.`val` < 6))" + . "\nORDER BY `test_table`.`val` ASC, `test_table`.`id` DESC"; + $actual = trim($this->waitForElement('byId', 'textSqlquery')->value()); + + /* Compare generated query */ + $this->assertEquals( + $expected, + $actual + ); + + /* Submit the query */ + $this->waitForElement('byCssSelector', 'input[value="Submit Query"]')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + $this->waitForElement('byCssSelector', 'table.table_results'); + + /* Assert Row 1 */ + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 1, 1) + ); + $this->assertEquals( + 3, + $this->getCellByTableClass('table_results', 1, 2) + ); + + /* Assert Row 2 */ + $this->assertEquals( + 6, + $this->getCellByTableClass('table_results', 2, 1) + ); + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 2, 2) + ); + + /* Assert Row 3 */ + $this->assertEquals( + 5, + $this->getCellByTableClass('table_results', 3, 1) + ); + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 3, 2) + ); + + /* Assert Row 4 */ + $this->assertEquals( + 7, + $this->getCellByTableClass('table_results', 4, 1) + ); + $this->assertEquals( + 5, + $this->getCellByTableClass('table_results', 4, 2) + ); + + /* Assert Row 5 */ + $this->assertEquals( + 3, + $this->getCellByTableClass('table_results', 5, 1) + ); + $this->assertEquals( + 5, + $this->getCellByTableClass('table_results', 5, 2) + ); + } +} \ No newline at end of file From 058546d29df1fca2e82f2a9d02766da01a0fb23c Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Tue, 15 Aug 2017 17:20:43 +0530 Subject: [PATCH 2/2] Add scrolling to bottom so that click goes through Signed-off-by: Deven Bansod --- test/selenium/PmaSeleniumQueryByExampleTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/selenium/PmaSeleniumQueryByExampleTest.php b/test/selenium/PmaSeleniumQueryByExampleTest.php index ca03efc669..37fe3b2339 100644 --- a/test/selenium/PmaSeleniumQueryByExampleTest.php +++ b/test/selenium/PmaSeleniumQueryByExampleTest.php @@ -145,6 +145,9 @@ class PmaSeleniumQueryByExampleTest extends PMA_SeleniumBase $actual ); + $this->scrollToBottom(); + sleep(1); + /* Submit the query */ $this->waitForElement('byCssSelector', 'input[value="Submit Query"]')->click(); $this->waitForElementNotPresent('byId', 'ajax_message_num_1');