Fix some more feature tests:

1. Added an attribute 'data-click-counter' in query execute button which gets incremented
   once query button is clicked up to 9 and then reset to 0. This is added just to support automation.
2. Locator for login_group_role is added and used to expand tree.
3. Functions for enabling and disable auto_commit and auto_rollback are made more precise.
4. Some scrolling problem is addressed in view_data_dml_query test.
5. Handled the stale element reference exception in query_tool_journey_test
This commit is contained in:
Shubham Agarwal 2019-11-20 12:50:04 +05:30 committed by Akshay Joshi
parent dc47c8f898
commit 425cc2a966
8 changed files with 82 additions and 60 deletions

View File

@ -429,7 +429,12 @@ class QueryToolJourneyTest(BaseFeatureTest):
ActionChains(self.driver).double_click(cell_el).perform()
ActionChains(self.driver).send_keys(new_value). \
send_keys(Keys.ENTER).perform()
# Check if the value was updated
# Finding element again to avoid stale element reference exception
cell_el = self.page.find_by_xpath(
"//div[contains(@style, 'top:0px')]//div[contains(@class, "
"'l{0} r{1}')]".format(cell_index, cell_index))
return int(cell_el.text) == new_value
def _check_can_add_row(self):
@ -438,6 +443,8 @@ class QueryToolJourneyTest(BaseFeatureTest):
def after(self):
self.page.close_query_tool()
self.page.remove_server(self.server)
test_utils.delete_table(
self.server, self.test_db, self.test_table_name)
test_utils.delete_table(
self.server, self.test_db, self.test_editable_table_name)
self.page.remove_server(self.server)

View File

@ -135,10 +135,10 @@ class QueryToolFeatureTest(BaseFeatureTest):
query_op.click()
# disable auto rollback only if they are enabled
self.uncheck_execute_option('auto_rollback')
self.page.uncheck_execute_option('auto_rollback')
# enable autocommit only if it's disabled
self.check_execute_option('auto_commit')
self.page.check_execute_option('auto_commit')
# close menu
query_op.click()
@ -343,7 +343,7 @@ CREATE TABLE public.{}();""".format(table_name)
query_op = self.page.find_by_css_selector(
QueryToolLocators.btn_query_dropdown)
query_op.click()
self.uncheck_execute_option('auto_commit')
self.page.uncheck_execute_option('auto_commit')
# close option
query_op.click()
@ -413,7 +413,7 @@ END;"""
query_op.click()
# Enable auto_commit if it is disabled
self.check_execute_option('auto_commit')
self.page.check_execute_option('auto_commit')
query_op.click()
@ -492,8 +492,8 @@ END;"""
query_op.click()
# uncheck auto commit and check auto-rollback
self.uncheck_execute_option('auto_commit')
self.check_execute_option('auto_rollback')
self.page.uncheck_execute_option('auto_commit')
self.page.check_execute_option('auto_rollback')
query_op.click()
@ -588,8 +588,8 @@ SELECT 1, pg_sleep(300)"""
query_op.click()
# enable auto-commit and disable auto-rollback
self.check_execute_option('auto_commit')
self.uncheck_execute_option('auto_rollback')
self.page.check_execute_option('auto_commit')
self.page.uncheck_execute_option('auto_rollback')
# close drop down
query_op.click()
# Execute query
@ -729,38 +729,6 @@ SELECT 1, pg_sleep(300)"""
self.page.clear_query_tool()
def check_execute_option(self, option):
""""This function will check auto commit or auto roll back based on
user input. If button is already checked, no action will be taken"""
if option == 'auto_commit':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_commit_check_status)
if 'visibility-hidden' in check_status.get_attribute('class'):
self.page.find_by_css_selector(QueryToolLocators.
btn_auto_commit).click()
if option == 'auto_rollback':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_rollback_check_status)
if 'visibility-hidden' in check_status.get_attribute('class'):
self.page.find_by_css_selector(QueryToolLocators.
btn_auto_rollback).click()
def uncheck_execute_option(self, option):
""""This function will uncheck auto commit or auto roll back based on
user input. If button is already unchecked, no action will be taken"""
if option == 'auto_commit':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_commit_check_status)
if 'visibility-hidden' not in check_status.get_attribute('class'):
self.page.find_by_css_selector(QueryToolLocators.
btn_auto_commit).click()
if option == 'auto_rollback':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_rollback_check_status)
if 'visibility-hidden' not in check_status.get_attribute('class'):
self.page.find_by_css_selector(QueryToolLocators.
btn_auto_rollback).click()
class WaitForAnyElementWithText(object):
def __init__(self, locator, text):

View File

@ -349,8 +349,6 @@ CREATE TABLE public.nonintpkey
self.page.wait_for_query_tool_loading_indicator_to_disappear()
result_row = self.page.find_by_xpath(xpath)
# Verify the List of actual values with the expected list
actual_list = list(config_check_data.keys())
for value in range(0, len(actual_list)):
@ -360,14 +358,15 @@ CREATE TABLE public.nonintpkey
for idx in actual_list:
while retry > 0:
try:
result_row = self.page.find_by_xpath(xpath)
element = \
result_row.find_element_by_class_name("r" + str(idx))
self.page.driver.execute_script(
"arguments[0].scrollIntoView(false)", element)
break
except Exception:
print("stale reference exception at id:", idx)
retry -= 1
self.page.driver.execute_script(
"arguments[0].scrollIntoView(false)", element)
time.sleep(0.4)
self.assertEquals(element.text, config_check_data[str(idx)][1])

View File

@ -13,6 +13,7 @@ import random
from regression.python_test_utils import test_utils
from regression.feature_utils.base_feature_test import BaseFeatureTest
from regression.feature_utils.locators import NavMenuLocators
from regression.feature_utils.tree_area_locators import TreeAreaLocators
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
@ -61,7 +62,8 @@ class CheckRoleMembershipControlFeatureTest(BaseFeatureTest):
self.page.expand_server_node(
self.server['name'], self.server['db_password'])
self.page.toggle_open_tree_item('Login/Group Roles')
self.page.select_tree_item(role)
self.page.click_a_tree_node(
role, TreeAreaLocators.sub_nodes_of_login_group_node)
def _check_role_membership_control(self):
self.page.driver.find_element_by_link_text(

View File

@ -240,7 +240,7 @@
</button>
<button id="btn-flash" data-test-selector="execute-refresh-button" type="button" class="btn btn-sm btn-secondary" style="width: 32px;"
title=""
tabindex="0" disabled>
tabindex="0" data-click-counter="0" disabled>
<i class="fa fa-bolt sql-icon-lg" aria-hidden="true"></i>
</button>
<button id="btn-query-dropdown" type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split"

View File

@ -1653,6 +1653,10 @@ define('tools.querytool', [
// Callback function for the flash button click.
on_flash: function() {
let data_click_counter = $('#btn-flash').attr('data-click-counter');
data_click_counter = (parseInt(data_click_counter) + 1)%10;
$('#btn-flash').attr('data-click-counter', data_click_counter);
this.handler.history_query_source = QuerySources.EXECUTE;
queryToolActions.executeQuery(this.handler);

View File

@ -180,9 +180,15 @@ class PgadminPage:
retry = 5
execute_button = self.find_by_css_selector(
QueryToolLocators.btn_execute_query_css)
first_click = execute_button.get_attribute('data-click-counter')
while retry > 0:
execute_button.click()
if self.wait_for_query_tool_loading_indicator_to_appear():
execute_button = self.find_by_css_selector(
QueryToolLocators.btn_execute_query_css)
second_click = execute_button.get_attribute(
'data-click-counter')
if first_click != second_click:
self.wait_for_query_tool_loading_indicator_to_appear()
break
else:
retry -= 1
@ -191,34 +197,65 @@ class PgadminPage:
def check_execute_option(self, option):
""""This function will check auto commit or auto roll back based on
user input. If button is already checked, no action will be taken"""
retry = 3
if option == 'auto_commit':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_commit_check_status)
if 'visibility-hidden' in check_status.get_attribute('class'):
self.find_by_css_selector(
QueryToolLocators.btn_auto_commit).click()
while retry > 0:
self.find_by_css_selector(
QueryToolLocators.btn_auto_commit).click()
time.sleep(0.2)
if 'visibility-hidden' not in \
check_status.get_attribute('class'):
break
else:
retry -= 1
if option == 'auto_rollback':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_rollback_check_status)
if 'visibility-hidden' in check_status.get_attribute('class'):
self.find_by_css_selector(
QueryToolLocators.btn_auto_rollback).click()
while retry > 0:
self.find_by_css_selector(
QueryToolLocators.btn_auto_rollback).click()
time.sleep(0.2)
if 'visibility-hidden' not in \
check_status.get_attribute('class'):
break
else:
retry -= 1
def uncheck_execute_option(self, option):
""""This function will uncheck auto commit or auto roll back based on
user input. If button is already unchecked, no action will be taken"""
retry = 3
if option == 'auto_commit':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_commit_check_status)
if 'visibility-hidden' not in check_status.get_attribute('class'):
self.find_by_css_selector(
QueryToolLocators.btn_auto_commit).click()
while retry > 0:
self.find_by_css_selector(
QueryToolLocators.btn_auto_commit).click()
time.sleep(0.2)
if 'visibility-hidden' in \
check_status.get_attribute('class'):
break
else:
retry -= 1
if option == 'auto_rollback':
check_status = self.driver.find_element_by_css_selector(
QueryToolLocators.btn_auto_rollback_check_status)
if 'visibility-hidden' not in check_status.get_attribute('class'):
self.find_by_css_selector(
QueryToolLocators.btn_auto_rollback).click()
while retry > 0:
self.find_by_css_selector(
QueryToolLocators.btn_auto_rollback).click()
time.sleep(0.2)
if 'visibility-hidden' in \
check_status.get_attribute('class'):
break
else:
retry -= 1
def close_data_grid(self):
self.driver.switch_to_default_content()
@ -273,9 +310,7 @@ class PgadminPage:
self.wait_for_elements_to_appear(
self.driver, list_of_element[index_of_element])
time.sleep(1)
self.driver.execute_script(
"arguments[0].click()",
list_of_element[index_of_element])
list_of_element[index_of_element].click()
operation_status = True
else:
print("{ERROR} - The required element with name: " + str(
@ -430,7 +465,10 @@ class PgadminPage:
if self.check_if_element_exist_by_xpath(
"//div[@class='ajs-header'and text()='INTERNAL SERVER "
"ERROR']", 1):
self.click_modal('OK')
try:
self.click_modal('OK')
except Exception:
pass
retry -= 1
else:
break

View File

@ -53,6 +53,10 @@ class TreeAreaLocators():
"contains(text(),'Functions')]]]]]]]]]]/" \
"following-sibling::ul/li/div//div/span[2]/span[2]"
sub_nodes_of_login_group_node = \
"//div[div[div[span[span[contains(text(),'Login/Group Roles')]]]]]" \
"/following::ul/li/div[@class='aciTreeLine']"
@staticmethod
def sub_nodes_of_a_server_node(server_name):
xpath = "//div[div[div[span[span[contains(text(),'%s')]]]]]/" \