diff --git a/web/pgadmin/feature_tests/xss_checks_file_manager_test.py b/web/pgadmin/feature_tests/xss_checks_file_manager_test.py index dfad314..131b340 100644 --- a/web/pgadmin/feature_tests/xss_checks_file_manager_test.py +++ b/web/pgadmin/feature_tests/xss_checks_file_manager_test.py @@ -8,6 +8,7 @@ ########################################################################## import os +import time from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By @@ -98,7 +99,11 @@ class CheckFileManagerFeatureTest(BaseFeatureTest): self.page.find_by_id("file-input-path").send_keys( Keys.RETURN ) + # Required sleep so that above action will be performed + time.sleep(0.05) contents = self.page.find_by_id("contents").get_attribute('innerHTML') + # Required sleep so that content should be read before cancel the dialog + time.sleep(0.05) self.page.click_modal('Cancel') self.page.wait_for_query_tool_loading_indicator_to_disappear() self._check_escaped_characters( diff --git a/web/regression/README b/web/regression/README index 88edbd8..7e668cf 100644 --- a/web/regression/README +++ b/web/regression/README @@ -46,7 +46,7 @@ General Information - 'pgAdmin4/web/pgadmin/browser/server_groups/tests/' shows an example of tree traversal of the pgAdmin modules and how the test folder is required for each individual module. - + - 'pgadmin/browser/server_groups/servers/tests/' directory will have separate file for each test-case: @@ -127,6 +127,15 @@ Python Tests: https://sites.google.com/a/chromium.org/chromedriver/downloads or a package manager and make sure it is in the PATH +- For feature tests to run on Firefox, geckodriver need to be installed; + - Get geckodriver from https://github.com/mozilla/geckodriver/releases. + - Extract the binary and run chmod +x geckodriver. + - Copy geckodriver into /usr/local/bin or make sure path of the + geckodriver must be specified in the PATH. + - Set the "default_browser" parameter in test_config file or pass the command + line option --default_browser. Supported browsers are "Chrome" and + "Firefox". + - The test framework is modular and pluggable and dynamically locates tests for modules which are discovered at runtime. All test cases are found and registered automatically by its module name in diff --git a/web/regression/feature_utils/app_starter.py b/web/regression/feature_utils/app_starter.py index 013f757..365f0d1 100644 --- a/web/regression/feature_utils/app_starter.py +++ b/web/regression/feature_utils/app_starter.py @@ -12,6 +12,7 @@ import signal import random import time +from selenium.common.exceptions import WebDriverException class AppStarter: @@ -41,10 +42,26 @@ class AppStarter: env=env ) - self.driver.get( - "http://" + self.app_config.DEFAULT_SERVER + ":" + - random_server_port - ) + def launch_browser(retry_count): + try: + self.driver.get( + "http://" + self.app_config.DEFAULT_SERVER + ":" + + random_server_port + ) + + except WebDriverException as e: + # In case of WebDriverException sleep for 1 second and retry + # again. Retry 10 times and if still app will not start then + # raise exception. + time.sleep(1) + if retry_count < 10: + retry_count = retry_count + 1 + launch_browser(retry_count) + else: + raise Exception('Unable to start python server even after ' + 'retrying 10 times.') + + launch_browser(0) def stop_app(self): """ This function stop the started app by killing process """ diff --git a/web/regression/feature_utils/pgadmin_page.py b/web/regression/feature_utils/pgadmin_page.py index be0f1c2..8ff6688 100644 --- a/web/regression/feature_utils/pgadmin_page.py +++ b/web/regression/feature_utils/pgadmin_page.py @@ -60,6 +60,8 @@ class PgadminPage: self.fill_input_by_field_name("port", server_config['port']) self.fill_input_by_field_name("username", server_config['username']) self.fill_input_by_field_name("password", server_config['db_password']) + # Required sleep to avoid "fe_sendauth" password error. + time.sleep(0.5) self.find_by_xpath("//button[contains(.,'Save')]").click() self.find_by_xpath( @@ -322,7 +324,7 @@ class PgadminPage: timeout=None): if timeout is None: timeout = self.timeout - return WebDriverWait(self.driver, timeout, 0.01).until( + return WebDriverWait(self.driver, timeout, 0.05).until( condition_met_function, "Timed out waiting for " + waiting_for_message ) diff --git a/web/regression/runtests.py b/web/regression/runtests.py index a20c8f6..b292155 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -181,13 +181,35 @@ def get_test_modules(arguments): exclude_pkgs += arguments['exclude'].split(',') if 'feature_tests' not in exclude_pkgs: - options = Options() - if test_setup.config_data: - if 'headless_chrome' in test_setup.config_data: - if test_setup.config_data['headless_chrome']: - options.add_argument("--headless") - options.add_argument("--window-size=1280x1024") - driver = webdriver.Chrome(chrome_options=options) + default_browser = 'chrome' + + # Check default browser provided through command line. If provided + # then use that browser as default browser else check for the setting + # provided in test_config.json file. + if ( + 'default_browser' in arguments and + arguments['default_browser'] is not None + ): + default_browser = arguments['default_browser'].lower() + elif ( + test_setup.config_data and + "default_browser" in test_setup.config_data + ): + default_browser = test_setup.config_data['default_browser'].lower() + + if default_browser == 'firefox': + profile = webdriver.FirefoxProfile() + profile.set_preference("dom.disable_beforeunload", True) + driver = webdriver.Firefox(firefox_profile=profile) + else: + options = Options() + if test_setup.config_data: + if 'headless_chrome' in test_setup.config_data: + if test_setup.config_data['headless_chrome']: + options.add_argument("--headless") + options.add_argument("--window-size=1280x1024") + driver = webdriver.Chrome(chrome_options=options) + app_starter = AppStarter(driver, config) app_starter.start_app() @@ -229,6 +251,10 @@ def add_arguments(): help='Skips execution of the test cases of particular package and ' 'sub-packages' ) + parser.add_argument( + '--default_browser', + help='Executes the feature test in specific browser' + ) arg = parser.parse_args() return arg @@ -341,7 +367,12 @@ if __name__ == '__main__': sys.stderr = StreamToLogger(stderr_logger, logging.ERROR) args = vars(add_arguments()) # Get test module list - test_module_list = get_test_modules(args) + try: + test_module_list = get_test_modules(args) + except Exception as e: + print(str(e)) + sys.exit(1) + # Login the test client test_utils.login_tester_account(test_client) diff --git a/web/regression/test_config.json.in b/web/regression/test_config.json.in index 54eeddb..711aca3 100644 --- a/web/regression/test_config.json.in +++ b/web/regression/test_config.json.in @@ -29,5 +29,6 @@ { "comment": "This is test update comment" } - ] + ], + "default_browser": "Chrome" }