mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
1) Fixes parallel test execution failures.
2) Added capability to pass browser-name via command line for parallel execution.
This commit is contained in:
parent
daad16ea93
commit
34fbe756e8
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -38,8 +40,9 @@ class CheckFileManagerFeatureTest(BaseFeatureTest):
|
|||||||
|
|
||||||
self.page.add_server(self.server)
|
self.page.add_server(self.server)
|
||||||
self.wait = WebDriverWait(self.page.driver, 10)
|
self.wait = WebDriverWait(self.page.driver, 10)
|
||||||
self.XSS_FILE = '/tmp/<img src=x ' + self.server['name'][:13] \
|
filename = self.server_information['type'] + \
|
||||||
+ '=alert("1")>.sql'
|
str(self.server_information['server_version'])
|
||||||
|
self.XSS_FILE = '/tmp/<img src=x ' + filename + '=alert("1")>.sql'
|
||||||
# Remove any previous file
|
# Remove any previous file
|
||||||
if os.path.isfile(self.XSS_FILE):
|
if os.path.isfile(self.XSS_FILE):
|
||||||
os.remove(self.XSS_FILE)
|
os.remove(self.XSS_FILE)
|
||||||
@ -115,9 +118,11 @@ class CheckFileManagerFeatureTest(BaseFeatureTest):
|
|||||||
|
|
||||||
self.page.click_modal('Cancel')
|
self.page.click_modal('Cancel')
|
||||||
self.page.wait_for_query_tool_loading_indicator_to_disappear()
|
self.page.wait_for_query_tool_loading_indicator_to_disappear()
|
||||||
|
filename = self.server_information['type'] + \
|
||||||
|
str(self.server_information['server_version'])
|
||||||
self._check_escaped_characters(
|
self._check_escaped_characters(
|
||||||
contents,
|
contents,
|
||||||
'<img src=x ' + self.server['name'][:13] +
|
'<img src=x ' + filename +
|
||||||
'=alert("1")>.sql', 'File manager'
|
'=alert("1")>.sql', 'File manager'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|||||||
from regression.python_test_utils import test_utils
|
from regression.python_test_utils import test_utils
|
||||||
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
||||||
from regression.feature_utils.locators import QueryToolLocators
|
from regression.feature_utils.locators import QueryToolLocators
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class QueryToolJourneyTest(BaseFeatureTest):
|
class QueryToolJourneyTest(BaseFeatureTest):
|
||||||
@ -329,13 +330,26 @@ class QueryToolJourneyTest(BaseFeatureTest):
|
|||||||
self.page.uncheck_execute_option("auto_commit")
|
self.page.uncheck_execute_option("auto_commit")
|
||||||
|
|
||||||
self._update_numeric_cell(2, 10)
|
self._update_numeric_cell(2, 10)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
self._commit_transaction()
|
self._commit_transaction()
|
||||||
|
|
||||||
# Turn on autocommit
|
# Turn on autocommit
|
||||||
query_options = self.page.find_by_css_selector(
|
retry = 3
|
||||||
QueryToolLocators.btn_query_dropdown)
|
while retry > 0:
|
||||||
query_options.click()
|
query_options = self.page.find_by_css_selector(
|
||||||
|
QueryToolLocators.btn_query_dropdown)
|
||||||
|
query_options.click()
|
||||||
|
expanded = query_options.get_attribute("aria-expanded")
|
||||||
|
if expanded == "false":
|
||||||
|
print("query option not yet expanded clicking commit again",
|
||||||
|
file=sys.stderr)
|
||||||
|
self._commit_transaction()
|
||||||
|
time.sleep(0.5)
|
||||||
|
query_options.click()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
retry -= 1
|
||||||
self.page.check_execute_option("auto_commit")
|
self.page.check_execute_option("auto_commit")
|
||||||
|
|
||||||
def _check_history_queries_and_icons(self, history_queries, history_icons):
|
def _check_history_queries_and_icons(self, history_queries, history_icons):
|
||||||
|
@ -581,6 +581,7 @@ SELECT 1, pg_sleep(300)"""
|
|||||||
commit_button = self.page.find_by_css_selector("#btn-commit")
|
commit_button = self.page.find_by_css_selector("#btn-commit")
|
||||||
if not commit_button.get_attribute('disabled'):
|
if not commit_button.get_attribute('disabled'):
|
||||||
commit_button.click()
|
commit_button.click()
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
query_op = self.page.find_by_css_selector(
|
query_op = self.page.find_by_css_selector(
|
||||||
QueryToolLocators.btn_query_dropdown)
|
QueryToolLocators.btn_query_dropdown)
|
||||||
|
@ -38,11 +38,12 @@ class CheckForXssFeatureTest(BaseFeatureTest):
|
|||||||
scenarios = [
|
scenarios = [
|
||||||
("Test XSS check for panels and query tool", dict())
|
("Test XSS check for panels and query tool", dict())
|
||||||
]
|
]
|
||||||
test_table_name = "<h1>X" + str(random.randint(1000, 3000))
|
|
||||||
# test_table_name = "<h1>X"
|
# test_table_name = "<h1>X"
|
||||||
test_type_name = '"<script>alert(1)</script>"'
|
test_type_name = '"<script>alert(1)</script>"'
|
||||||
|
|
||||||
def before(self):
|
def before(self):
|
||||||
|
self.test_table_name = "<h1>X" + str(random.randint(1000, 3000))
|
||||||
|
|
||||||
test_utils.create_type(
|
test_utils.create_type(
|
||||||
self.server, self.test_db, self.test_type_name,
|
self.server, self.test_db, self.test_type_name,
|
||||||
['"<script>alert(1)</script>" "char"',
|
['"<script>alert(1)</script>" "char"',
|
||||||
@ -166,7 +167,7 @@ class CheckForXssFeatureTest(BaseFeatureTest):
|
|||||||
"td[2]").get_attribute('innerHTML')
|
"td[2]").get_attribute('innerHTML')
|
||||||
retry = 0
|
retry = 0
|
||||||
except WebDriverException as e:
|
except WebDriverException as e:
|
||||||
print("Exception in dependent tab {0}")
|
print("Exception in dependent tab {0}".format(retry))
|
||||||
self.page.click_tab("Dependencies")
|
self.page.click_tab("Dependencies")
|
||||||
if retry == 1:
|
if retry == 1:
|
||||||
raise e
|
raise e
|
||||||
|
@ -1241,7 +1241,7 @@ def is_parallel_ui_tests(args):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_selenium_grid_status_and_browser_list(selenoid_url):
|
def get_selenium_grid_status_and_browser_list(selenoid_url, arguments):
|
||||||
"""
|
"""
|
||||||
This function checks selenoid status for given url
|
This function checks selenoid status for given url
|
||||||
:param selrnoid_url:
|
:param selrnoid_url:
|
||||||
@ -1253,9 +1253,18 @@ def get_selenium_grid_status_and_browser_list(selenoid_url):
|
|||||||
try:
|
try:
|
||||||
selenoid_status = get_selenium_grid_status_json(selenoid_url)
|
selenoid_status = get_selenium_grid_status_json(selenoid_url)
|
||||||
if selenoid_status:
|
if selenoid_status:
|
||||||
|
# Get available browsers from selenoid
|
||||||
available_browsers = selenoid_status["browsers"]
|
available_browsers = selenoid_status["browsers"]
|
||||||
list_of_browsers = test_setup.config_data['selenoid_config'][
|
|
||||||
'browsers_list']
|
# Get browser list provided in input by user
|
||||||
|
if 'default_browser' in arguments and \
|
||||||
|
arguments['default_browser'] is not None:
|
||||||
|
default_browser = arguments['default_browser'].lower()
|
||||||
|
list_of_browsers = [{"name": default_browser,
|
||||||
|
"version": None}]
|
||||||
|
else:
|
||||||
|
list_of_browsers = test_setup.config_data['selenoid_config'][
|
||||||
|
'browsers_list']
|
||||||
|
|
||||||
for browser in list_of_browsers:
|
for browser in list_of_browsers:
|
||||||
if browser["name"].lower() in available_browsers.keys():
|
if browser["name"].lower() in available_browsers.keys():
|
||||||
@ -1467,8 +1476,8 @@ def get_selenium_grid_status_json(selenoid_url):
|
|||||||
if isinstance(selenoid_status, dict):
|
if isinstance(selenoid_status, dict):
|
||||||
return selenoid_status
|
return selenoid_status
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Unable to find Selenoid Status.Kindly check url passed -'{0}'".
|
print("Unable to find Selenoid Status.Kindly check url passed -'{0}'."
|
||||||
format(selenoid_url))
|
"Check parsing errors in test_config.json".format(selenoid_url))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -499,13 +499,14 @@ def execute_test(test_module_list_passed, server_passed, driver_passed):
|
|||||||
if connection:
|
if connection:
|
||||||
test_utils.drop_database(connection, test_db_name)
|
test_utils.drop_database(connection, test_db_name)
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
# Delete test server
|
# Delete test server
|
||||||
test_utils.delete_test_server(test_client)
|
test_utils.delete_test_server(test_client)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
print(str(exc))
|
print(str(exc))
|
||||||
print("Exception in {0}".format(threading.current_thread().ident))
|
print("Exception in {0} {1}".format(
|
||||||
|
threading.current_thread().ident,
|
||||||
|
threading.currentThread().getName()))
|
||||||
finally:
|
finally:
|
||||||
# Delete web-driver instance
|
# Delete web-driver instance
|
||||||
thread_name = "parallel_tests" + server_passed['name']
|
thread_name = "parallel_tests" + server_passed['name']
|
||||||
@ -616,7 +617,7 @@ def run_sequential_tests(url_client, servers_details, sequential_tests_lists,
|
|||||||
print(str(exc))
|
print(str(exc))
|
||||||
finally:
|
finally:
|
||||||
# Clean driver object created
|
# Clean driver object created
|
||||||
driver_object.quit()
|
test_utils.quit_webdriver(driver_object)
|
||||||
|
|
||||||
|
|
||||||
def print_test_results():
|
def print_test_results():
|
||||||
@ -739,91 +740,94 @@ if __name__ == '__main__':
|
|||||||
# Check if feature tests included & parallel tests switch passed
|
# Check if feature tests included & parallel tests switch passed
|
||||||
if test_utils.is_feature_test_included(args) and \
|
if test_utils.is_feature_test_included(args) and \
|
||||||
test_utils.is_parallel_ui_tests(args):
|
test_utils.is_parallel_ui_tests(args):
|
||||||
|
try:
|
||||||
|
# Get selenium config dict
|
||||||
|
selenoid_config = test_setup.config_data['selenoid_config']
|
||||||
|
|
||||||
# Get selenium config dict
|
# Set DEFAULT_SERVER value
|
||||||
selenoid_config = test_setup.config_data['selenoid_config']
|
default_server = selenoid_config['pgAdmin_default_server']
|
||||||
|
os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"] = str(default_server)
|
||||||
|
config.DEFAULT_SERVER = str(default_server)
|
||||||
|
|
||||||
# Set DEFAULT_SERVER value
|
# Get hub url
|
||||||
default_server = selenoid_config['pgAdmin_default_server']
|
hub_url = selenoid_config['selenoid_url']
|
||||||
os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"] = str(default_server)
|
|
||||||
config.DEFAULT_SERVER = str(default_server)
|
|
||||||
|
|
||||||
# Get hub url
|
# Get selenium grid status & list of available browser out passed
|
||||||
hub_url = selenoid_config['selenoid_url']
|
selenium_grid_status, list_of_browsers \
|
||||||
|
= test_utils.get_selenium_grid_status_and_browser_list(hub_url,
|
||||||
|
args)
|
||||||
|
|
||||||
# Get selenium grid status & list of available browser out passed
|
# Execute tests if selenium-grid is up
|
||||||
selenium_grid_status, list_of_browsers \
|
if selenium_grid_status and len(list_of_browsers) > 0:
|
||||||
= test_utils.get_selenium_grid_status_and_browser_list(hub_url)
|
app_starter_local = None
|
||||||
|
# run across browsers
|
||||||
|
for browser_info in list_of_browsers:
|
||||||
|
try:
|
||||||
|
# browser info
|
||||||
|
browser_name, browser_version = \
|
||||||
|
test_utils.get_browser_details(browser_info,
|
||||||
|
hub_url)
|
||||||
|
|
||||||
# Execute tests if selenium-grid is up
|
# test lists can be executed in parallel & sequentially
|
||||||
if selenium_grid_status and len(list_of_browsers) > 0:
|
parallel_tests, sequential_tests = \
|
||||||
app_starter_local = None
|
test_utils.get_parallel_sequential_module_list(
|
||||||
# run across browsers
|
test_module_list)
|
||||||
for browser_info in list_of_browsers:
|
|
||||||
try:
|
|
||||||
# browser info
|
|
||||||
browser_name, browser_version = \
|
|
||||||
test_utils.get_browser_details(browser_info, hub_url)
|
|
||||||
|
|
||||||
# tests lists can be executed in parallel & sequentially
|
# Print test summary
|
||||||
parallel_tests, sequential_tests = \
|
test_utils.print_test_summary(
|
||||||
test_utils.get_parallel_sequential_module_list(
|
test_module_list, parallel_tests, sequential_tests,
|
||||||
test_module_list)
|
browser_name, browser_version)
|
||||||
|
|
||||||
# Print test summary
|
# Create app form source code
|
||||||
test_utils.print_test_summary(test_module_list,
|
app_starter_local = AppStarter(None, config)
|
||||||
parallel_tests,
|
client_url = app_starter_local.start_app()
|
||||||
sequential_tests,
|
|
||||||
browser_name,
|
|
||||||
browser_version)
|
|
||||||
|
|
||||||
# Create app form source code
|
# Running Parallel tests
|
||||||
app_starter_local = AppStarter(None, config)
|
if len(parallel_tests) > 0:
|
||||||
client_url = app_starter_local.start_app()
|
parallel_sessions = \
|
||||||
|
int(selenoid_config['max_parallel_sessions'])
|
||||||
|
|
||||||
# Running Parallel tests
|
run_parallel_tests(
|
||||||
if len(parallel_tests) > 0:
|
client_url, servers_info, parallel_tests,
|
||||||
parallel_sessions = int(selenoid_config[
|
browser_name, browser_version,
|
||||||
'max_parallel_sessions'])
|
parallel_sessions)
|
||||||
|
|
||||||
run_parallel_tests(client_url, servers_info,
|
# Sequential Tests
|
||||||
parallel_tests, browser_name,
|
if len(sequential_tests) > 0:
|
||||||
browser_version, parallel_sessions)
|
run_sequential_tests(
|
||||||
|
client_url, servers_info, sequential_tests,
|
||||||
|
browser_name, browser_version)
|
||||||
|
|
||||||
# Wait till all threads started in parallel are finished
|
# Clean up environment
|
||||||
while True:
|
if app_starter_local:
|
||||||
try:
|
app_starter_local.stop_app()
|
||||||
if threading.activeCount() <= 1:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
time.sleep(10)
|
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc(file=sys.stderr)
|
|
||||||
print(str(e))
|
|
||||||
|
|
||||||
# Sequential Tests
|
# Pause before printing result in order
|
||||||
if len(sequential_tests) > 0:
|
# not to mix output
|
||||||
run_sequential_tests(client_url, servers_info,
|
time.sleep(5)
|
||||||
sequential_tests, browser_name,
|
|
||||||
browser_version)
|
|
||||||
|
|
||||||
# Clean up environment
|
# Print note for completion of execution in a browser.
|
||||||
if app_starter_local:
|
print(
|
||||||
app_starter_local.stop_app()
|
"\n============= Test execution with {0} is "
|
||||||
|
"completed.=============".format(browser_name),
|
||||||
|
file=sys.stderr)
|
||||||
|
print_test_results()
|
||||||
|
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
if app_starter_local:
|
if app_starter_local:
|
||||||
app_starter_local.stop_app()
|
app_starter_local.stop_app()
|
||||||
if handle_cleanup:
|
if handle_cleanup:
|
||||||
handle_cleanup()
|
handle_cleanup()
|
||||||
# Pause before printing result in order not to mix output
|
else:
|
||||||
time.sleep(5)
|
|
||||||
# Print note for completion of execution in a browser.
|
|
||||||
print(
|
print(
|
||||||
"\n============= Test execution with {0} is "
|
"\n============= Either Selenium Grid is NOT up OR"
|
||||||
"completed.=============".format(browser_name),
|
" browser list is 0 =============", file=sys.stderr)
|
||||||
file=sys.stderr)
|
failure = True
|
||||||
print_test_results()
|
except Exception as exc:
|
||||||
|
# Print exception stack trace
|
||||||
|
traceback.print_exc(file=sys.stderr)
|
||||||
|
print(str(exc))
|
||||||
|
failure = True
|
||||||
del os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"]
|
del os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user