1) Fixes parallel test execution failures.

2) Added capability to pass browser-name via command line for parallel execution.
This commit is contained in:
Yogesh Mahajan 2020-06-22 13:05:13 +05:30 committed by Akshay Joshi
parent daad16ea93
commit 34fbe756e8
6 changed files with 120 additions and 86 deletions

View File

@ -9,6 +9,8 @@
from __future__ import print_function
import os
import random
import string
import sys
import time
@ -38,8 +40,9 @@ class CheckFileManagerFeatureTest(BaseFeatureTest):
self.page.add_server(self.server)
self.wait = WebDriverWait(self.page.driver, 10)
self.XSS_FILE = '/tmp/<img src=x ' + self.server['name'][:13] \
+ '=alert("1")>.sql'
filename = self.server_information['type'] + \
str(self.server_information['server_version'])
self.XSS_FILE = '/tmp/<img src=x ' + filename + '=alert("1")>.sql'
# Remove any previous file
if os.path.isfile(self.XSS_FILE):
os.remove(self.XSS_FILE)
@ -115,9 +118,11 @@ class CheckFileManagerFeatureTest(BaseFeatureTest):
self.page.click_modal('Cancel')
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(
contents,
'&lt;img src=x ' + self.server['name'][:13] +
'&lt;img src=x ' + filename +
'=alert("1")&gt;.sql', 'File manager'
)

View File

@ -17,6 +17,7 @@ from selenium.webdriver.support.ui import WebDriverWait
from regression.python_test_utils import test_utils
from regression.feature_utils.base_feature_test import BaseFeatureTest
from regression.feature_utils.locators import QueryToolLocators
import time
class QueryToolJourneyTest(BaseFeatureTest):
@ -329,13 +330,26 @@ class QueryToolJourneyTest(BaseFeatureTest):
self.page.uncheck_execute_option("auto_commit")
self._update_numeric_cell(2, 10)
time.sleep(0.5)
self._commit_transaction()
# Turn on autocommit
query_options = self.page.find_by_css_selector(
QueryToolLocators.btn_query_dropdown)
query_options.click()
retry = 3
while retry > 0:
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")
def _check_history_queries_and_icons(self, history_queries, history_icons):

View File

@ -581,6 +581,7 @@ SELECT 1, pg_sleep(300)"""
commit_button = self.page.find_by_css_selector("#btn-commit")
if not commit_button.get_attribute('disabled'):
commit_button.click()
time.sleep(0.5)
query_op = self.page.find_by_css_selector(
QueryToolLocators.btn_query_dropdown)

View File

@ -38,11 +38,12 @@ class CheckForXssFeatureTest(BaseFeatureTest):
scenarios = [
("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_type_name = '"<script>alert(1)</script>"'
def before(self):
self.test_table_name = "<h1>X" + str(random.randint(1000, 3000))
test_utils.create_type(
self.server, self.test_db, self.test_type_name,
['"<script>alert(1)</script>" "char"',
@ -166,7 +167,7 @@ class CheckForXssFeatureTest(BaseFeatureTest):
"td[2]").get_attribute('innerHTML')
retry = 0
except WebDriverException as e:
print("Exception in dependent tab {0}")
print("Exception in dependent tab {0}".format(retry))
self.page.click_tab("Dependencies")
if retry == 1:
raise e

View File

@ -1241,7 +1241,7 @@ def is_parallel_ui_tests(args):
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
:param selrnoid_url:
@ -1253,9 +1253,18 @@ def get_selenium_grid_status_and_browser_list(selenoid_url):
try:
selenoid_status = get_selenium_grid_status_json(selenoid_url)
if selenoid_status:
# Get available browsers from selenoid
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:
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):
return selenoid_status
except Exception as e:
print("Unable to find Selenoid Status.Kindly check url passed -'{0}'".
format(selenoid_url))
print("Unable to find Selenoid Status.Kindly check url passed -'{0}'."
"Check parsing errors in test_config.json".format(selenoid_url))
return None

View File

@ -499,13 +499,14 @@ def execute_test(test_module_list_passed, server_passed, driver_passed):
if connection:
test_utils.drop_database(connection, test_db_name)
connection.close()
# Delete test server
test_utils.delete_test_server(test_client)
except Exception as exc:
traceback.print_exc(file=sys.stderr)
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:
# Delete web-driver instance
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))
finally:
# Clean driver object created
driver_object.quit()
test_utils.quit_webdriver(driver_object)
def print_test_results():
@ -739,91 +740,94 @@ if __name__ == '__main__':
# Check if feature tests included & parallel tests switch passed
if test_utils.is_feature_test_included(args) and \
test_utils.is_parallel_ui_tests(args):
try:
# Get selenium config dict
selenoid_config = test_setup.config_data['selenoid_config']
# Get selenium config dict
selenoid_config = test_setup.config_data['selenoid_config']
# Set DEFAULT_SERVER value
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
default_server = selenoid_config['pgAdmin_default_server']
os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"] = str(default_server)
config.DEFAULT_SERVER = str(default_server)
# Get hub url
hub_url = selenoid_config['selenoid_url']
# Get hub url
hub_url = selenoid_config['selenoid_url']
# Get selenium grid status & list of available browser out passed
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
selenium_grid_status, list_of_browsers \
= test_utils.get_selenium_grid_status_and_browser_list(hub_url)
# Execute tests if selenium-grid is up
if selenium_grid_status and len(list_of_browsers) > 0:
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
if selenium_grid_status and len(list_of_browsers) > 0:
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)
# test lists can be executed in parallel & sequentially
parallel_tests, sequential_tests = \
test_utils.get_parallel_sequential_module_list(
test_module_list)
# tests lists can be executed in parallel & sequentially
parallel_tests, sequential_tests = \
test_utils.get_parallel_sequential_module_list(
test_module_list)
# Print test summary
test_utils.print_test_summary(
test_module_list, parallel_tests, sequential_tests,
browser_name, browser_version)
# Print test summary
test_utils.print_test_summary(test_module_list,
parallel_tests,
sequential_tests,
browser_name,
browser_version)
# Create app form source code
app_starter_local = AppStarter(None, config)
client_url = app_starter_local.start_app()
# Create app form source code
app_starter_local = AppStarter(None, config)
client_url = app_starter_local.start_app()
# Running Parallel tests
if len(parallel_tests) > 0:
parallel_sessions = \
int(selenoid_config['max_parallel_sessions'])
# Running Parallel tests
if len(parallel_tests) > 0:
parallel_sessions = int(selenoid_config[
'max_parallel_sessions'])
run_parallel_tests(
client_url, servers_info, parallel_tests,
browser_name, browser_version,
parallel_sessions)
run_parallel_tests(client_url, servers_info,
parallel_tests, browser_name,
browser_version, parallel_sessions)
# Sequential Tests
if len(sequential_tests) > 0:
run_sequential_tests(
client_url, servers_info, sequential_tests,
browser_name, browser_version)
# Wait till all threads started in parallel are finished
while True:
try:
if threading.activeCount() <= 1:
break
else:
time.sleep(10)
except Exception as e:
traceback.print_exc(file=sys.stderr)
print(str(e))
# Clean up environment
if app_starter_local:
app_starter_local.stop_app()
# Sequential Tests
if len(sequential_tests) > 0:
run_sequential_tests(client_url, servers_info,
sequential_tests, browser_name,
browser_version)
# Pause before printing result in order
# not to mix output
time.sleep(5)
# Clean up environment
if app_starter_local:
app_starter_local.stop_app()
# Print note for completion of execution in a browser.
print(
"\n============= Test execution with {0} is "
"completed.=============".format(browser_name),
file=sys.stderr)
print_test_results()
except SystemExit:
if app_starter_local:
app_starter_local.stop_app()
if handle_cleanup:
handle_cleanup()
# Pause before printing result in order not to mix output
time.sleep(5)
# Print note for completion of execution in a browser.
except SystemExit:
if app_starter_local:
app_starter_local.stop_app()
if handle_cleanup:
handle_cleanup()
else:
print(
"\n============= Test execution with {0} is "
"completed.=============".format(browser_name),
file=sys.stderr)
print_test_results()
"\n============= Either Selenium Grid is NOT up OR"
" browser list is 0 =============", file=sys.stderr)
failure = True
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"]
else:
try: