2017-06-13 03:50:41 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2018-01-05 04:42:49 -06:00
|
|
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
2017-06-13 03:50:41 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
import pyperclip
|
|
|
|
|
|
|
|
from selenium.webdriver import ActionChains
|
2017-07-20 14:47:40 -05:00
|
|
|
from selenium.webdriver.common.keys import Keys
|
2017-06-13 03:50:41 -05:00
|
|
|
|
|
|
|
from regression.python_test_utils import test_utils
|
|
|
|
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
|
|
|
|
|
|
|
|
|
|
|
class QueryToolJourneyTest(BaseFeatureTest):
|
|
|
|
"""
|
|
|
|
Tests the path through the query tool
|
|
|
|
"""
|
|
|
|
|
|
|
|
scenarios = [
|
|
|
|
("Tests the path through the query tool", dict())
|
|
|
|
]
|
|
|
|
|
|
|
|
def before(self):
|
2018-02-09 06:57:37 -06:00
|
|
|
connection = test_utils.get_db_connection(
|
|
|
|
self.server['db'],
|
|
|
|
self.server['username'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.server['host'],
|
|
|
|
self.server['port']
|
|
|
|
)
|
2017-06-13 03:50:41 -05:00
|
|
|
test_utils.drop_database(connection, "acceptance_test_db")
|
|
|
|
test_utils.create_database(self.server, "acceptance_test_db")
|
2018-02-09 06:57:37 -06:00
|
|
|
test_utils.create_table(
|
|
|
|
self.server, "acceptance_test_db", "test_table")
|
2017-06-13 03:50:41 -05:00
|
|
|
self.page.add_server(self.server)
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self._navigate_to_query_tool()
|
2017-08-29 08:57:56 -05:00
|
|
|
|
|
|
|
self._execute_query(
|
|
|
|
"SELECT * FROM test_table ORDER BY value"
|
|
|
|
)
|
2017-06-13 03:50:41 -05:00
|
|
|
|
|
|
|
self._test_copies_rows()
|
|
|
|
self._test_copies_columns()
|
|
|
|
self._test_history_tab()
|
|
|
|
|
|
|
|
def _test_copies_rows(self):
|
|
|
|
pyperclip.copy("old clipboard contents")
|
|
|
|
self.page.driver.switch_to.default_content()
|
2018-02-09 06:57:37 -06:00
|
|
|
self.page.driver.switch_to_frame(
|
|
|
|
self.page.driver.find_element_by_tag_name("iframe"))
|
|
|
|
self.page.find_by_xpath(
|
|
|
|
"//*[contains(@class, 'slick-row')]/*[1]").click()
|
2017-06-13 03:50:41 -05:00
|
|
|
self.page.find_by_xpath("//*[@id='btn-copy-row']").click()
|
|
|
|
|
2017-11-20 07:50:47 -06:00
|
|
|
self.assertEqual('"Some-Name"\t"6"\t"some info"',
|
2017-06-13 03:50:41 -05:00
|
|
|
pyperclip.paste())
|
|
|
|
|
|
|
|
def _test_copies_columns(self):
|
|
|
|
pyperclip.copy("old clipboard contents")
|
|
|
|
|
|
|
|
self.page.driver.switch_to.default_content()
|
2018-02-09 06:57:37 -06:00
|
|
|
self.page.driver.switch_to_frame(
|
|
|
|
self.page.driver.find_element_by_tag_name("iframe"))
|
|
|
|
self.page.find_by_xpath(
|
|
|
|
"//*[@data-test='output-column-header' and "
|
|
|
|
"contains(., 'some_column')]"
|
|
|
|
).click()
|
2017-06-13 03:50:41 -05:00
|
|
|
self.page.find_by_xpath("//*[@id='btn-copy-row']").click()
|
|
|
|
|
2017-11-20 07:50:47 -06:00
|
|
|
self.assertTrue('"Some-Name"' in pyperclip.paste())
|
|
|
|
self.assertTrue('"Some-Other-Name"' in pyperclip.paste())
|
|
|
|
self.assertTrue('"Yet-Another-Name"' in pyperclip.paste())
|
2017-06-13 03:50:41 -05:00
|
|
|
|
|
|
|
def _test_history_tab(self):
|
|
|
|
self.__clear_query_tool()
|
|
|
|
editor_input = self.page.find_by_id("output-panel")
|
|
|
|
self.page.click_element(editor_input)
|
2017-08-09 06:09:06 -05:00
|
|
|
self._execute_query("SELECT * FROM table_that_doesnt_exist")
|
2017-06-13 03:50:41 -05:00
|
|
|
|
2017-08-09 06:09:06 -05:00
|
|
|
self.page.click_tab("Query History")
|
2018-02-09 06:57:37 -06:00
|
|
|
selected_history_entry = self.page.find_by_css_selector(
|
|
|
|
"#query_list .selected")
|
|
|
|
self.assertIn("SELECT * FROM table_that_doesnt_exist",
|
|
|
|
selected_history_entry.text)
|
2017-07-20 14:50:37 -05:00
|
|
|
failed_history_detail_pane = self.page.find_by_id("query_detail")
|
2017-08-09 06:09:06 -05:00
|
|
|
|
2018-02-09 06:57:37 -06:00
|
|
|
self.assertIn(
|
|
|
|
"Error Message relation \"table_that_doesnt_exist\" "
|
|
|
|
"does not exist", failed_history_detail_pane.text
|
|
|
|
)
|
2017-07-20 14:47:40 -05:00
|
|
|
ActionChains(self.page.driver) \
|
|
|
|
.send_keys(Keys.ARROW_DOWN) \
|
|
|
|
.perform()
|
2018-02-09 06:57:37 -06:00
|
|
|
selected_history_entry = self.page.find_by_css_selector(
|
|
|
|
"#query_list .selected")
|
|
|
|
self.assertIn("SELECT * FROM test_table ORDER BY value",
|
|
|
|
selected_history_entry.text)
|
2017-07-20 14:47:40 -05:00
|
|
|
selected_history_detail_pane = self.page.find_by_id("query_detail")
|
2018-02-09 06:57:37 -06:00
|
|
|
self.assertIn("SELECT * FROM test_table ORDER BY value",
|
|
|
|
selected_history_detail_pane.text)
|
|
|
|
newly_selected_history_entry = self.page.find_by_xpath(
|
|
|
|
"//*[@id='query_list']/ul/li[2]")
|
2017-07-20 14:47:40 -05:00
|
|
|
self.page.click_element(newly_selected_history_entry)
|
|
|
|
selected_history_detail_pane = self.page.find_by_id("query_detail")
|
2018-02-09 06:57:37 -06:00
|
|
|
self.assertIn("SELECT * FROM table_that_doesnt_exist",
|
|
|
|
selected_history_detail_pane.text)
|
2017-08-09 06:09:06 -05:00
|
|
|
|
|
|
|
self.__clear_query_tool()
|
|
|
|
|
|
|
|
self.page.click_element(editor_input)
|
2017-08-29 08:57:56 -05:00
|
|
|
|
|
|
|
self.page.fill_codemirror_area_with("SELECT * FROM hats")
|
2017-08-09 06:09:06 -05:00
|
|
|
for _ in range(15):
|
2017-08-29 08:57:56 -05:00
|
|
|
self.page.find_by_id("btn-flash").click()
|
|
|
|
self.page.wait_for_query_tool_loading_indicator_to_disappear()
|
2017-08-09 06:09:06 -05:00
|
|
|
|
|
|
|
self.page.click_tab("Query History")
|
|
|
|
|
2018-02-09 06:57:37 -06:00
|
|
|
query_we_need_to_scroll_to = self.page.find_by_xpath(
|
|
|
|
"//*[@id='query_list']/ul/li[17]")
|
2017-08-09 06:09:06 -05:00
|
|
|
|
|
|
|
self.page.click_element(query_we_need_to_scroll_to)
|
|
|
|
|
|
|
|
for _ in range(17):
|
|
|
|
ActionChains(self.page.driver) \
|
|
|
|
.send_keys(Keys.ARROW_DOWN) \
|
|
|
|
.perform()
|
|
|
|
|
|
|
|
self._assert_clickable(query_we_need_to_scroll_to)
|
2017-06-13 03:50:41 -05:00
|
|
|
|
2017-07-20 14:47:40 -05:00
|
|
|
self.__clear_query_tool()
|
|
|
|
self.page.click_element(editor_input)
|
2017-08-29 08:57:56 -05:00
|
|
|
self.page.fill_codemirror_area_with("SELECT * FROM hats")
|
2017-07-20 14:47:40 -05:00
|
|
|
for _ in range(15):
|
2017-08-29 08:57:56 -05:00
|
|
|
self.page.find_by_id("btn-flash").click()
|
|
|
|
self.page.wait_for_query_tool_loading_indicator_to_disappear()
|
2017-07-20 14:47:40 -05:00
|
|
|
|
|
|
|
self.page.click_tab("History")
|
2017-07-21 04:57:29 -05:00
|
|
|
query_we_need_to_scroll_to = self.page.find_by_xpath(
|
|
|
|
"//*[@id='query_list']/ul/li[17]"
|
|
|
|
)
|
2017-07-20 14:47:40 -05:00
|
|
|
for _ in range(17):
|
|
|
|
ActionChains(self.page.driver) \
|
|
|
|
.send_keys(Keys.ARROW_DOWN) \
|
|
|
|
.perform()
|
|
|
|
self._assert_clickable(query_we_need_to_scroll_to)
|
2017-06-27 09:55:57 -05:00
|
|
|
|
2017-06-13 03:50:41 -05:00
|
|
|
def __clear_query_tool(self):
|
2017-07-21 04:57:29 -05:00
|
|
|
self.page.click_element(
|
|
|
|
self.page.find_by_xpath("//*[@id='btn-clear-dropdown']")
|
|
|
|
)
|
|
|
|
ActionChains(self.driver)\
|
|
|
|
.move_to_element(self.page.find_by_xpath("//*[@id='btn-clear']"))\
|
|
|
|
.perform()
|
|
|
|
self.page.click_element(
|
|
|
|
self.page.find_by_xpath("//*[@id='btn-clear']")
|
|
|
|
)
|
2017-06-13 03:50:41 -05:00
|
|
|
self.page.click_modal('Yes')
|
|
|
|
|
|
|
|
def _navigate_to_query_tool(self):
|
|
|
|
self.page.toggle_open_tree_item(self.server['name'])
|
|
|
|
self.page.toggle_open_tree_item('Databases')
|
|
|
|
self.page.toggle_open_tree_item('acceptance_test_db')
|
2017-06-23 08:07:31 -05:00
|
|
|
self.page.open_query_tool()
|
2017-06-13 03:50:41 -05:00
|
|
|
|
|
|
|
def _execute_query(self, query):
|
2017-08-29 08:57:56 -05:00
|
|
|
self.page.fill_codemirror_area_with(query)
|
2017-06-13 03:50:41 -05:00
|
|
|
self.page.find_by_id("btn-flash").click()
|
|
|
|
|
2017-07-20 14:47:40 -05:00
|
|
|
def _assert_clickable(self, element):
|
|
|
|
self.page.click_element(element)
|
|
|
|
|
2017-06-13 03:50:41 -05:00
|
|
|
def after(self):
|
|
|
|
self.page.close_query_tool()
|
|
|
|
self.page.remove_server(self.server)
|
|
|
|
|
|
|
|
connection = test_utils.get_db_connection(self.server['db'],
|
|
|
|
self.server['username'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.server['host'],
|
|
|
|
self.server['port'])
|
|
|
|
test_utils.drop_database(connection, "acceptance_test_db")
|