From e71c08d79266a3a3e099838a2b6dcd9195cd173d Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Fri, 11 Aug 2017 15:23:53 +0530 Subject: [PATCH 1/2] Add Selenium tests for typing and executing SQL query * Adds separate tests for Server SQL, Database SQL, Table SQL query pages * Add tests for inline-edit on SQL results page Signed-off-by: Deven Bansod --- test/selenium/PmaSeleniumSqlQueryTest.php | 242 ++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 test/selenium/PmaSeleniumSqlQueryTest.php diff --git a/test/selenium/PmaSeleniumSqlQueryTest.php b/test/selenium/PmaSeleniumSqlQueryTest.php new file mode 100644 index 0000000000..b11c62aa54 --- /dev/null +++ b/test/selenium/PmaSeleniumSqlQueryTest.php @@ -0,0 +1,242 @@ +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), (3), (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 testServerSqlQuery() + { + $this->waitForElement('byPartialLinkText', 'SQL')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + // Minimum wait + sleep(1); + + // Dynamic wait + $this->waitUntil(function () { + if ($this->byCssSelector('div.CodeMirror')) { + return true; + } + return null; + }, 5000); + $this->typeInTextArea( + 'SET @t1=1, @t2=2, @t3:=4;' + . 'SELECT 1 as `id`, @t1, @t2, @t3, @t4 := @t1+@t2+@t3;', + 2 + ); + $this->byId('button_submit_query')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + $this->waitForElement('byCssSelector', 'table.table_results'); + $this->assertEquals( + 1, + $this->getCellByTableClass('table_results', 1, 1) + ); + $this->assertEquals( + 1, + $this->getCellByTableClass('table_results', 1, 2) + ); + $this->assertEquals( + 2, + $this->getCellByTableClass('table_results', 1, 3) + ); + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 1, 4) + ); + $this->assertEquals( + 7, + $this->getCellByTableClass('table_results', 1, 5) + ); + + // test inline edit button + $this->_testInlineEdit(); + } + + /** + * Test typing a SQL query on Database SQL page and submitting it + * + * @return void + */ + public function testDatabaseSqlQuery() + { + // 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', 'SQL')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + // Minimum wait + sleep(1); + + // Dynamic wait + $this->waitUntil(function () { + if ($this->byCssSelector('div.CodeMirror')) { + return true; + } + return null; + }, 5000); + $this->typeInTextArea( + 'SHOW TABLE STATUS', + 2 + ); + $this->byId('button_submit_query')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + $this->waitForElement('byCssSelector', 'table.table_results'); + $this->assertEquals( + 'test_table', + $this->getCellByTableClass('table_results', 1, 1) + ); + $this->assertEquals( + 'InnoDB', + $this->getCellByTableClass('table_results', 1, 2) + ); + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 1, 5) + ); + + // test inline edit button + $this->_testInlineEdit(); + } + + /** + * Test typing a SQL query on Table SQL page and submitting it + * + * @return void + */ + public function testTableSqlQuery() + { + $this->navigateTable('test_table'); + + $this->waitForElement('byPartialLinkText', 'SQL')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + // Minimum wait + sleep(1); + + // Dynamic wait + $this->waitUntil(function () { + if ($this->byCssSelector('div.CodeMirror')) { + return true; + } + return null; + }, 5000); + $this->typeInTextArea( + 'SELECT * FROM `test_table` WHERE `val` NOT IN (2, 3);', + 2 + ); + $this->byId('button_submit_query')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + $this->waitForElement('byCssSelector', 'table.table_results'); + $this->assertEquals( + 3, + $this->getCellByTableClass('table_results', 1, 5) + ); + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 2, 5) + ); + $this->assertEquals( + 4, + $this->getCellByTableClass('table_results', 1, 6) + ); + $this->assertEquals( + 5, + $this->getCellByTableClass('table_results', 2, 6) + ); + + // test inline edit button + $this->_testInlineEdit(); + } + + private function _testInlineEdit() + { + $this->waitForElement('byCssSelector', 'a.inline_edit_sql')->click(); + // empty current query + $this->typeInTextArea( + '', + 3 + ); + + // type in next sql query + $this->typeInTextArea( + 'SELECT 1', + 3 + ); + + $this->byId('sql_query_edit_save')->click(); + $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + + $this->waitForElement('byCssSelector', 'table.table_results'); + $this->assertEquals( + 1, + $this->getCellByTableClass('table_results', 1, 1) + ); + } +} From 7e04e04631638fe8294f36410e27812759419fc3 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Fri, 11 Aug 2017 16:11:06 +0530 Subject: [PATCH 2/2] Add a small sleep to avoid stale element exception Signed-off-by: Deven Bansod --- test/selenium/PmaSeleniumSqlQueryTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/selenium/PmaSeleniumSqlQueryTest.php b/test/selenium/PmaSeleniumSqlQueryTest.php index b11c62aa54..603f55a3f9 100644 --- a/test/selenium/PmaSeleniumSqlQueryTest.php +++ b/test/selenium/PmaSeleniumSqlQueryTest.php @@ -233,6 +233,8 @@ class PMA_SeleniumSqlQueryTest extends PMA_SeleniumBase $this->byId('sql_query_edit_save')->click(); $this->waitForElementNotPresent('byId', 'ajax_message_num_1'); + sleep(1); + $this->waitForElement('byCssSelector', 'table.table_results'); $this->assertEquals( 1,