Resolve the PG datatype feature test flakiness and make for a nice buttery crust.

This commit is contained in:
George Gelashvili
2017-06-07 14:26:42 +01:00
committed by Dave Page
parent 8d8e7dab3c
commit f89aec867a
3 changed files with 37 additions and 29 deletions

View File

@@ -6,7 +6,6 @@
# This software is released under the PostgreSQL Licence
#
##########################################################################
from selenium.webdriver import ActionChains
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
@@ -90,30 +89,28 @@ class PGDataypeFeatureTest(BaseFeatureTest):
self.page.driver.find_element_by_link_text("Tools").click()
self.page.find_by_partial_link_text("Query Tool").click()
self.page.fill_codemirror_area_with(query)
self.page.find_by_id("btn-flash").click()
wait = WebDriverWait(self.page.driver, 5)
element = wait.until(EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME, 'iframe')))
wait.until(EC.presence_of_element_located(
(By.XPATH, "//*[@id='0']//*[@id='datagrid']/div[5]/div/div[1]/div[2]/span")))
if element:
self.page.fill_codemirror_area_with(query)
self.page.find_by_id("btn-flash").click()
wait.until(EC.presence_of_element_located(
(By.XPATH, "//*[@id='0']//*[@id='datagrid']/div[5]/div/div[1]/div[2]/span")))
# For every sample data-type value, check the expected output.
cnt = 2
for val in expected_output:
try:
source_code = self.page.find_by_xpath(
"//*[@id='0']//*[@id='datagrid']/div[5]/div/div[1]/div[" + str(cnt) + "]/span"
).get_attribute('innerHTML')
# For every sample data-type value, check the expected output.
cnt = 2
for val in expected_output:
try:
source_code = self.page.find_by_xpath(
"//*[@id='0']//*[@id='datagrid']/div[5]/div/div[1]/div[" + str(cnt) + "]/span"
).get_attribute('innerHTML')
PGDataypeFeatureTest.check_result(
source_code,
expected_output[cnt - 2]
)
cnt += 1
except TimeoutException:
assert False, "{0} does not match with {1}".format(val, expected_output[cnt])
PGDataypeFeatureTest.check_result(
source_code,
expected_output[cnt - 2]
)
cnt += 1
except TimeoutException:
assert False, "{0} does not match with {1}".format(val, expected_output[cnt])
@staticmethod
def check_result(source_code, string_to_find):

View File

@@ -149,8 +149,6 @@ class CheckForXssFeatureTest(BaseFeatureTest):
def _check_xss_in_query_tool(self):
self.page.driver.find_element_by_link_text("Tools").click()
self.page.find_by_partial_link_text("Query Tool").click()
time.sleep(3)
self.page.driver.switch_to.frame(self.page.driver.find_element_by_tag_name('iframe'))
self.page.fill_codemirror_area_with("select '<img src=\"x\" onerror=\"console.log(1)\">'")
time.sleep(1)
self.page.find_by_id("btn-flash").click()

View File

@@ -27,7 +27,7 @@ class PgadminPage:
def __init__(self, driver, app_config):
self.driver = driver
self.app_config = app_config
self.timeout = 30
self.timeout = 20
self.app_start_timeout = 60
def reset_layout(self):
@@ -127,14 +127,27 @@ class PgadminPage:
# For long text, if we try to execute send_keys and perform back to back, then the actions are
# not executed properly as the driver can send only 50 to 60 characters. To avoid this, sleep
# on the basis of content length.
self.find_by_xpath(
"//pre[contains(@class,'CodeMirror-line')]/../../../*[contains(@class,'CodeMirror-code')]").click()
def find_codemirror(driver):
try:
driver.switch_to.default_content()
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
element = driver.find_element_by_xpath(
"//pre[contains(@class,'CodeMirror-line')]/../../../*[contains(@class,'CodeMirror-code')]")
if element.is_displayed() and element.is_enabled():
return element
except (NoSuchElementException, WebDriverException):
return False
WebDriverWait(self.driver, timeout=self.timeout, poll_frequency=0.01).\
until(find_codemirror, "Timed out waiting for codemirror to appear").\
click()
time.sleep(1)
action = ActionChains(self.driver)
action.send_keys(field_content)
action.perform()
sleep_time = math.ceil(len(field_content) / 50)
time.sleep(sleep_time)
action.perform()
time.sleep(1)
def click_tab(self, tab_name):
self.find_by_xpath("//*[contains(@class,'wcTabTop')]//*[contains(@class,'wcPanelTab') "