2017-03-16 09:27:55 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2023-01-02 00:23:55 -06:00
|
|
|
# Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2017-03-16 09:27:55 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
2017-03-09 09:34:51 -06:00
|
|
|
import errno
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
2017-05-02 06:00:30 -05:00
|
|
|
from copy import deepcopy
|
|
|
|
|
2017-02-22 06:41:28 -06:00
|
|
|
import config as app_config
|
|
|
|
from pgadmin.utils.route import BaseTestGenerator
|
|
|
|
from regression.feature_utils.pgadmin_page import PgadminPage
|
2018-10-17 05:50:22 -05:00
|
|
|
from regression.python_test_utils import test_utils
|
2017-02-22 06:41:28 -06:00
|
|
|
|
|
|
|
|
|
|
|
class BaseFeatureTest(BaseTestGenerator):
|
2017-03-09 09:34:51 -06:00
|
|
|
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
2017-02-22 06:41:28 -06:00
|
|
|
def setUp(self):
|
2017-05-02 06:00:30 -05:00
|
|
|
self.server = deepcopy(self.server)
|
|
|
|
self.server['name'] += ' Feature Tests'
|
2021-05-27 00:31:25 -05:00
|
|
|
if app_config.SERVER_MODE and not self.parallel_ui_tests:
|
2018-02-19 05:12:35 -06:00
|
|
|
self.skipTest(
|
|
|
|
"Currently, config is set to start pgadmin in server mode. "
|
|
|
|
"This test doesn't know username and password so doesn't work "
|
|
|
|
"in server mode"
|
|
|
|
)
|
2017-02-22 06:41:28 -06:00
|
|
|
|
2017-03-01 07:20:06 -06:00
|
|
|
self.page = PgadminPage(self.driver, app_config)
|
2017-03-09 09:34:51 -06:00
|
|
|
try:
|
2021-05-27 00:31:25 -05:00
|
|
|
if self.parallel_ui_tests:
|
|
|
|
self.page.login_to_app(self.server['login_details'])
|
2018-10-17 05:50:22 -05:00
|
|
|
test_utils.reset_layout_db()
|
2017-04-18 07:28:45 -05:00
|
|
|
self.page.driver.switch_to.default_content()
|
2017-03-09 09:34:51 -06:00
|
|
|
self.page.wait_for_app()
|
|
|
|
self.page.wait_for_spinner_to_disappear()
|
2018-10-17 05:50:22 -05:00
|
|
|
self.page.refresh_page()
|
2017-03-09 09:34:51 -06:00
|
|
|
self.page.wait_for_spinner_to_disappear()
|
|
|
|
self.before()
|
2018-02-19 05:12:35 -06:00
|
|
|
except Exception:
|
2017-03-09 09:34:51 -06:00
|
|
|
self._screenshot()
|
|
|
|
raise
|
2017-02-22 06:41:28 -06:00
|
|
|
|
|
|
|
def runTest(self):
|
2020-07-24 01:16:30 -05:00
|
|
|
# To be implemented by child classes
|
2017-03-09 09:34:51 -06:00
|
|
|
pass
|
|
|
|
|
|
|
|
def before(self):
|
2020-07-24 01:16:30 -05:00
|
|
|
# To be implemented by child classes
|
2017-03-09 09:34:51 -06:00
|
|
|
pass
|
|
|
|
|
|
|
|
def after(self):
|
2020-07-24 01:16:30 -05:00
|
|
|
# To be implemented by child classes
|
2017-03-09 09:34:51 -06:00
|
|
|
pass
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
python3_failures = hasattr(self, '_outcome') and self.any_step_failed()
|
|
|
|
|
2023-03-27 01:08:57 -05:00
|
|
|
if python3_failures:
|
2017-03-09 09:34:51 -06:00
|
|
|
self._screenshot()
|
|
|
|
|
|
|
|
self.after()
|
|
|
|
|
|
|
|
def any_step_failed(self):
|
2023-05-10 00:02:47 -05:00
|
|
|
if hasattr(self._outcome, 'errors'):
|
|
|
|
for step in self._outcome.errors:
|
|
|
|
if step[1] is not None:
|
|
|
|
return True
|
2017-03-09 09:34:51 -06:00
|
|
|
return False
|
|
|
|
|
|
|
|
def current_test_failed(self):
|
2018-02-19 05:12:35 -06:00
|
|
|
all_failures = self._resultForDoCleanups.errors + \
|
|
|
|
self._resultForDoCleanups.failures
|
2017-03-09 09:34:51 -06:00
|
|
|
for failure in all_failures:
|
|
|
|
if failure[0] == self:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _screenshot(self):
|
2017-03-15 17:06:04 -05:00
|
|
|
screenshots_directory = '{0}/../screenshots'.format(self.CURRENT_PATH)
|
2018-02-19 05:12:35 -06:00
|
|
|
screenshots_server_directory = '{0}/{1}'.format(
|
|
|
|
screenshots_directory,
|
|
|
|
self.server["name"].replace(" ", "_")
|
|
|
|
)
|
2017-03-09 09:34:51 -06:00
|
|
|
|
2017-03-15 17:06:04 -05:00
|
|
|
self.ensure_directory_exists(screenshots_directory)
|
|
|
|
self.ensure_directory_exists(screenshots_server_directory)
|
|
|
|
|
|
|
|
date = datetime.now().strftime("%Y.%m.%d_%H.%M.%S")
|
2022-11-18 22:43:41 -06:00
|
|
|
python_version = sys.version.split(" ", maxsplit=1)[0]
|
2017-03-15 17:06:04 -05:00
|
|
|
|
|
|
|
self.page.driver.save_screenshot(
|
2018-02-19 05:12:35 -06:00
|
|
|
'{0}/{1}-{2}-Python-{3}.png'.format(
|
|
|
|
screenshots_server_directory,
|
|
|
|
self.__class__.__name__,
|
|
|
|
date,
|
|
|
|
python_version
|
|
|
|
)
|
|
|
|
)
|
2017-03-15 17:06:04 -05:00
|
|
|
|
|
|
|
def ensure_directory_exists(self, path):
|
2017-03-09 09:34:51 -06:00
|
|
|
try:
|
|
|
|
os.mkdir(path)
|
|
|
|
except OSError as e:
|
2020-06-26 02:48:27 -05:00
|
|
|
if e.errno != errno.EEXIST:
|
2017-03-09 09:34:51 -06:00
|
|
|
raise
|