def expand_database_node(self, server_name, server_password, name_of_database): """will expand database node under databases node""" db_node_expanded_status = False if self.expand_databases_node(server_name, server_password): sub_nodes_of_databases_node = self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_databases_node(server_name)) index_of_required_db_node = self.get_index_of_element( sub_nodes_of_databases_node, name_of_database) expansion_status = self.get_expansion_status_of_node_element( self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_databases_node_exp_status( server_name))[index_of_required_db_node]) if not expansion_status: self.driver.execute_script( "arguments[0].scrollIntoView()", sub_nodes_of_databases_node[index_of_required_db_node]) webdriver.ActionChains(self.driver).double_click( sub_nodes_of_databases_node[index_of_required_db_node] ).perform() if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.sub_nodes_of_database_node( name_of_database)): db_node_expanded_status = True else: db_node_expanded_status = True else: print("The databases/previous nodes not expanded", file=sys.stderr) return db_node_expanded_status
def toggle_open_tables_node(self, server_name, server_password, name_of_database, name_of_schema_node): """will expand tables node under schema node""" node_expanded_successfully = False if self.toggle_open_schema_node(server_name, server_password, name_of_database, name_of_schema_node): sub_nodes_of_schema_node = self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_schema_node(name_of_database)) sub_nodes_of_schema_node_exp_status = self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_schema_node_exp_status( name_of_database)) index_of_tables_node = self.get_index_of_element( sub_nodes_of_schema_node, "Tables") expansion_status = self.get_expansion_status_of_node_element( sub_nodes_of_schema_node_exp_status[index_of_tables_node]) if not expansion_status: self.driver.execute_script( "arguments[0].scrollIntoView()", sub_nodes_of_schema_node[index_of_tables_node]) webdriver.ActionChains(self.driver).double_click( sub_nodes_of_schema_node[index_of_tables_node]).perform() if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.sub_nodes_of_tables_node): node_expanded_successfully = True else: node_expanded_successfully = True else: print( "(expand_tables_node) schema/previous nodes " "are not expanded", file=sys.stderr) return node_expanded_successfully
def _function_node_expandable(self): self.page.expand_schema_child_node("Server", self.server['name'], self.server['db_password'], self.test_db, 'public', "Functions") function_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.function_node(self.function_name + "()")) function_node.click()
def _perform_test_for_table(self, table_name, config_data_local): table_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.table_node(table_name)) table_node.click() # Open Object -> View/Edit data self._view_data_grid(table_name) time.sleep(3) self.page.wait_for_query_tool_loading_indicator_to_disappear() # Run test to insert a new row in table with default values self._add_row(config_data_local) self._verify_row_data(row=1, config_check_data=config_data_local['add']) # Run test to copy/paste a row self._copy_paste_row(config_data_local) self._update_row(config_data_local) self.page.click_tab("id-messages", rc_dock=True) self._verify_messsages("") self.page.click_tab("id-dataoutput", rc_dock=True) updated_row_data = { i: config_data_local['update'][i] if i in config_data_local['update'] else val for i, val in config_data_local['add'].items() } self._verify_row_data(row=1, config_check_data=updated_row_data) self.page.close_data_grid()
def _open_maintenance_dialogue(self): if self.test_level == 'table': self.page.expand_tables_node("Server", self.server['name'], self.server['db_password'], self.database_name, 'public') table_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.table_node(self.table_name)) status = False if table_node: status = True self.assertTrue( status, "Table name {} is not visible/selected".format( self.table_name)) table_node.click() else: self.page.expand_database_node("Server", self.server['name'], self.server['db_password'], self.database_name) self.page.retry_click( (By.LINK_TEXT, NavMenuLocators.tools_menu_link_text), (By.CSS_SELECTOR, NavMenuLocators.maintenance_obj_css)) maintenance_obj = self.wait.until( EC.visibility_of_element_located( (By.CSS_SELECTOR, NavMenuLocators.maintenance_obj_css))) maintenance_obj.click() self.page.check_if_element_exist_by_xpath( NavMenuLocators.maintenance_operation, 10)
def _tables_node_expandable(self): self.page.expand_tables_node("Server", self.server['name'], self.server['db_password'], self.test_db, 'public') table_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.table_node(self.test_table_name)) table_node.click()
def _role_node_expandable(self, role): self.page.expand_server_child_node("Server", self.server['name'], self.server['db_password'], 'Login/Group Roles') role_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.role_node(role)) role_node.click()
def _check_datatype(self): # Slick grid does not render all the column if viewport is not enough # wide. So execute test as batch of queries. self.page.click_a_tree_node( self.test_db, TreeAreaLocators.sub_nodes_of_databases_node(self.server['name'])) self.page.open_query_tool() self._create_enum_type() for batch in config_data: query = self.construct_select_query(batch) self.page.execute_query(query) wait = WebDriverWait(self.page.driver, 5) # wait for the visibility of the grid to appear wait.until( EC.visibility_of_element_located( (By.XPATH, "//*[contains(@class,'column-type')]"))) wait.until( EC.visibility_of_element_located( (By.XPATH, "//*[contains(@class,'column-type') and " "contains(.,'{}')]".format(batch['datatype'][0])))) canvas = wait.until( EC.presence_of_element_located( (By.CSS_SELECTOR, QueryToolLocators.query_output_canvas_css))) # For every sample data-type value, check the expected output. cnt = 2 cells = canvas.find_elements_by_css_selector( QueryToolLocators.query_output_cells) # remove first element as it is row number. cells.pop(0) for val, cell, datatype in zip(batch['output'], cells, batch['datatype']): expected_output = batch['output'][cnt - 2] if not self._is_datatype_available_in_current_database( datatype): cnt += 1 continue if datatype in ('tstzrange', 'tstzrange[]'): expected_output = expected_output.format( **dict([('tz', self.timezone_hh_mm)])) try: source_code = cell.text PGDataypeFeatureTest.check_result(datatype, source_code, expected_output) cnt += 1 except TimeoutException: assert False,\ "for datatype {0}\n{1} does not match with {2}".format( datatype, val, expected_output ) self.page.clear_query_tool()
def _create_table(self): self.test_table_name = "test_table" + str(random.randint(1000, 3000)) test_utils.create_table(self.server, self.test_db, self.test_table_name) self.page.expand_tables_node("Server", self.server['name'], self.server['db_password'], self.test_db, 'public') table_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.table_node(self.test_table_name)) table_node.click()
def expand_database_node(self, server_name, server_password, name_of_database): """will expand database node under databases node""" db_node_expanded_status = False retry = 5 if self.expand_databases_node(server_name, server_password): sub_nodes_of_databases_node = self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_databases_node(server_name)) index_of_required_db_node = self.get_index_of_element( sub_nodes_of_databases_node, name_of_database) expansion_status = self.get_expansion_status_of_node_element( self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_databases_node_exp_status( server_name))[index_of_required_db_node]) if not expansion_status: self.driver.execute_script( "arguments[0].scrollIntoView()", sub_nodes_of_databases_node[index_of_required_db_node]) while retry > 0: webdriver.ActionChains(self.driver).double_click( sub_nodes_of_databases_node[index_of_required_db_node] ).perform() if self.check_if_element_exist_by_xpath( "//div[@class='ajs-header'and text()='INTERNAL SERVER " "ERROR']", 1): try: self.click_modal('OK') except Exception: pass retry -= 1 else: break if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.sub_nodes_of_database_node( name_of_database)): db_node_expanded_status = True else: db_node_expanded_status = True else: print("The databases/previous nodes not expanded", file=sys.stderr) return db_node_expanded_status
def expand_databases_node(self, server_name, server_password): """will expand databases node under server node""" databases_node_expanded = False if self.expand_server_node(server_name, server_password): if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.sub_nodes_of_a_server_node(server_name)): subnodes_of_server_node = self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_a_server_node(server_name)) subnode_of_server_node_exp_status = self.find_by_xpath_list( TreeAreaLocators.sub_nodes_of_a_server_node_exp_status( server_name)) index_of_databases_node = self.get_index_of_element( subnodes_of_server_node, "Databases") time.sleep(2) expansion_status = self.get_expansion_status_of_node_element( subnode_of_server_node_exp_status[index_of_databases_node]) if not expansion_status: retry = 5 while retry > 0: webdriver.ActionChains(self.driver).double_click( subnodes_of_server_node[index_of_databases_node]. find_element_by_xpath( ".//*[@class='aciTreeItem']")).perform() if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.sub_nodes_of_databases_node( server_name), 3): databases_node_expanded = True break else: retry -= 1 else: databases_node_expanded = True else: print("The server/previous nodes not expanded", file=sys.stderr) return databases_node_expanded
def test_view_data_tool_button(self): self.page.expand_tables_node("Servers", self.server['name'], self.server['db_password'], self.test_db, "public") table_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.table_node(self.test_table_name)) table_node.click() self.assertTrue( self.page.retry_click( (By.CSS_SELECTOR, BrowserToolBarLocators.view_table_data_button_css), (By.CSS_SELECTOR, BrowserToolBarLocators.view_data_panel_css)), 'View/Edit Data tab did not open after clicking View/Edit button.') self.page.close_query_tool(prompt=False)
def test_view_data_tool_button(self): self.page.click_a_tree_node( self.test_db, TreeAreaLocators.sub_nodes_of_databases_node(self.server['name'])) self.page.toggle_open_schema_node(self.server['name'], self.server['db_password'], self.test_db, 'public') self.page.toggle_open_tables_node(self.server['name'], self.server['db_password'], self.test_db, 'public') self.page.click_a_tree_node(self.test_table_name, TreeAreaLocators.sub_nodes_of_tables_node) self.page.retry_click( (By.CSS_SELECTOR, BrowserToolBarLocators.view_table_data_button_css), (By.CSS_SELECTOR, BrowserToolBarLocators.view_data_panel_css))
def expand_server_node(self, server_name, server_password): """will expand a particular server node""" server_node_expansion_status = False if self.toggle_open_servers_group(): if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.server_group_sub_nodes): subnodes_of_servers = self.find_by_xpath_list( TreeAreaLocators.server_group_sub_nodes) subnodes_of_servers_expansion_status = \ self.find_by_xpath_list( TreeAreaLocators. server_group_sub_nodes_exp_status) index_of_server_node = self.get_index_of_element( subnodes_of_servers, server_name) if not self.check_server_is_connected(index_of_server_node): if self.click_and_connect_server( subnodes_of_servers[index_of_server_node], server_password): server_node_expansion_status = True else: print( "(expand_server_node)The server node is " "not expanded", file=sys.stderr) else: if not self.get_expansion_status_of_node_element( subnodes_of_servers_expansion_status[ index_of_server_node]): webdriver.ActionChains(self.driver).double_click( subnodes_of_servers[index_of_server_node]).perform( ) if self.wait_for_elements_to_appear( self.driver, TreeAreaLocators.sub_nodes_of_a_server_node( server_name), 30): server_node_expansion_status = True else: server_node_expansion_status = True else: print("(expand_server_node) The Servers node is" " not expanded", file=sys.stderr) return server_node_expansion_status
def runTest(self): self.test_table_name = "test_table" + str(random.randint(1000, 3000)) test_utils.create_table(self.server, self.test_db, self.test_table_name) self.page.expand_tables_node("Server", self.server['name'], self.server['db_password'], self.test_db, 'public') table_node = self.page.check_if_element_exists_with_scroll( TreeAreaLocators.table_node(self.test_table_name)) table_node.click() self.page.click_tab("SQL") # Wait till data is displayed in SQL Tab self.assertTrue( self.page.check_if_element_exist_by_xpath( "//*[contains(@class,'CodeMirror-lines') and " "contains(.,'CREATE TABLE IF NOT EXISTS public.%s')]" % self.test_table_name, 10), "No data displayed in SQL tab")