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 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,
'&lt;img src=x ' + self.server['name'][:13] + '&lt;img src=x ' + filename +
'=alert("1")&gt;.sql', 'File manager' '=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.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
retry = 3
while retry > 0:
query_options = self.page.find_by_css_selector( query_options = self.page.find_by_css_selector(
QueryToolLocators.btn_query_dropdown) QueryToolLocators.btn_query_dropdown)
query_options.click() 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):

View File

@ -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)

View File

@ -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

View File

@ -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,7 +1253,16 @@ 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"]
# 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'][ list_of_browsers = test_setup.config_data['selenoid_config'][
'browsers_list'] 'browsers_list']
@ -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

View File

@ -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,7 +740,7 @@ 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 # Get selenium config dict
selenoid_config = test_setup.config_data['selenoid_config'] selenoid_config = test_setup.config_data['selenoid_config']
@ -753,7 +754,8 @@ if __name__ == '__main__':
# Get selenium grid status & list of available browser out passed # Get selenium grid status & list of available browser out passed
selenium_grid_status, list_of_browsers \ selenium_grid_status, list_of_browsers \
= test_utils.get_selenium_grid_status_and_browser_list(hub_url) = test_utils.get_selenium_grid_status_and_browser_list(hub_url,
args)
# Execute tests if selenium-grid is up # Execute tests if selenium-grid is up
if selenium_grid_status and len(list_of_browsers) > 0: if selenium_grid_status and len(list_of_browsers) > 0:
@ -763,19 +765,18 @@ if __name__ == '__main__':
try: try:
# browser info # browser info
browser_name, browser_version = \ browser_name, browser_version = \
test_utils.get_browser_details(browser_info, hub_url) test_utils.get_browser_details(browser_info,
hub_url)
# tests lists can be executed in parallel & sequentially # test lists can be executed in parallel & sequentially
parallel_tests, sequential_tests = \ parallel_tests, sequential_tests = \
test_utils.get_parallel_sequential_module_list( test_utils.get_parallel_sequential_module_list(
test_module_list) test_module_list)
# Print test summary # Print test summary
test_utils.print_test_summary(test_module_list, test_utils.print_test_summary(
parallel_tests, test_module_list, parallel_tests, sequential_tests,
sequential_tests, browser_name, browser_version)
browser_name,
browser_version)
# Create app form source code # Create app form source code
app_starter_local = AppStarter(None, config) app_starter_local = AppStarter(None, config)
@ -783,47 +784,50 @@ if __name__ == '__main__':
# Running Parallel tests # Running Parallel tests
if len(parallel_tests) > 0: if len(parallel_tests) > 0:
parallel_sessions = int(selenoid_config[ parallel_sessions = \
'max_parallel_sessions']) int(selenoid_config['max_parallel_sessions'])
run_parallel_tests(client_url, servers_info, run_parallel_tests(
parallel_tests, browser_name, client_url, servers_info, parallel_tests,
browser_version, parallel_sessions) browser_name, browser_version,
parallel_sessions)
# 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))
# Sequential Tests # Sequential Tests
if len(sequential_tests) > 0: if len(sequential_tests) > 0:
run_sequential_tests(client_url, servers_info, run_sequential_tests(
sequential_tests, browser_name, client_url, servers_info, sequential_tests,
browser_version) browser_name, browser_version)
# Clean up environment # Clean up environment
if app_starter_local: if app_starter_local:
app_starter_local.stop_app() app_starter_local.stop_app()
except SystemExit: # Pause before printing result in order
if app_starter_local: # not to mix output
app_starter_local.stop_app()
if handle_cleanup:
handle_cleanup()
# Pause before printing result in order not to mix output
time.sleep(5) time.sleep(5)
# Print note for completion of execution in a browser. # Print note for completion of execution in a browser.
print( print(
"\n============= Test execution with {0} is " "\n============= Test execution with {0} is "
"completed.=============".format(browser_name), "completed.=============".format(browser_name),
file=sys.stderr) file=sys.stderr)
print_test_results() print_test_results()
except SystemExit:
if app_starter_local:
app_starter_local.stop_app()
if handle_cleanup:
handle_cleanup()
else:
print(
"\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"] del os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"]
else: else:
try: try: