diff --git a/test/gui/envs.txt b/test/gui/envs.txt index a24aacfdad5..8d35c7da6d4 100644 --- a/test/gui/envs.txt +++ b/test/gui/envs.txt @@ -1 +1 @@ -XDG_CONFIG_HOME=/tmp/owncloudtest/ \ No newline at end of file +XDG_CONFIG_HOME=/tmp/owncloudtest/.config diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index c6c0fba0b19..604b99ac8c4 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -32,7 +32,7 @@ isLinux, ) from helpers.api.utils import url_join -from helpers.FilesHelper import prefix_path_namespace +from helpers.FilesHelper import prefix_path_namespace, cleanup_created_paths from datetime import datetime from pageObjects.Toolbar import Toolbar from pageObjects.AccountSetting import AccountSetting @@ -238,6 +238,8 @@ def teardown_client(): shutil.rmtree(prefix_path_namespace(entry.path)) except Exception as e: test.log(f'Failed to delete{entry.name}. Reason: {e}.') + # cleanup paths created outside of the temporary directory during the test + cleanup_created_paths() def close_dialogs(): diff --git a/test/gui/shared/scripts/helpers/ConfigHelper.py b/test/gui/shared/scripts/helpers/ConfigHelper.py index f1c93ca9552..bf95c904077 100644 --- a/test/gui/shared/scripts/helpers/ConfigHelper.py +++ b/test/gui/shared/scripts/helpers/ConfigHelper.py @@ -11,6 +11,8 @@ def read_env_file(): env_path = os.path.abspath(os.path.join(script_path, '..', '..', '..', 'envs.txt')) with open(env_path, "rt", encoding="UTF-8") as f: for line in f: + if not line.strip(): + continue if line.startswith('#'): continue key, value = line.split('=', 1) @@ -51,6 +53,13 @@ def getConfigHome(): return os.path.join(get_config_from_env_file("XDG_CONFIG_HOME"), "ownCloud") +def get_default_home_dir(): + if isWindows(): + return getWinUserHome() + elif isLinux(): + return os.environ.get("HOME") + + # map environment variables to config keys CONFIG_ENV_MAP = { 'localBackendUrl': 'BACKEND_HOST', @@ -67,6 +76,11 @@ def getConfigHome(): 'ocis': 'OCIS', } +DEFAULT_PATH_CONFIG = { + 'custom_lib': os.path.abspath('../shared/scripts/custom_lib'), + 'home_dir': get_default_home_dir(), +} + # default config values CONFIG = { 'localBackendUrl': 'https://localhost:9200/', @@ -81,10 +95,10 @@ def getConfigHome(): 'clientConfigDir': getConfigHome(), 'guiTestReportDir': os.path.abspath('../reports'), 'ocis': False, - 'custom_lib': os.path.abspath('../shared/scripts/custom_lib'), } +CONFIG.update(DEFAULT_PATH_CONFIG) -READONLY_CONFIG = list(CONFIG_ENV_MAP.keys()) +READONLY_CONFIG = list(CONFIG_ENV_MAP.keys()) + list(DEFAULT_PATH_CONFIG.keys()) def init_config(): diff --git a/test/gui/shared/scripts/helpers/FilesHelper.py b/test/gui/shared/scripts/helpers/FilesHelper.py index 66259fde055..22449a3bd71 100644 --- a/test/gui/shared/scripts/helpers/FilesHelper.py +++ b/test/gui/shared/scripts/helpers/FilesHelper.py @@ -1,6 +1,7 @@ import os import re import ctypes +import shutil from helpers.ConfigHelper import isWindows @@ -104,3 +105,23 @@ def get_file_size_on_disk(resource_path): def get_file_size(resource_path): return os.stat(resource_path).st_size + + +# temp paths created outside of the temporary directory during the test +CREATED_PATHS = [] + + +def remember_path(path): + global CREATED_PATHS + CREATED_PATHS.append(path) + + +def cleanup_created_paths(): + global CREATED_PATHS + for path in CREATED_PATHS: + if os.path.exists(path): + if os.path.isdir(path): + shutil.rmtree(prefix_path_namespace(path)) + else: + os.unlink(prefix_path_namespace(path)) + CREATED_PATHS = [] diff --git a/test/gui/shared/scripts/helpers/SetupClientHelper.py b/test/gui/shared/scripts/helpers/SetupClientHelper.py index dbafd93105e..834cac4a99e 100644 --- a/test/gui/shared/scripts/helpers/SetupClientHelper.py +++ b/test/gui/shared/scripts/helpers/SetupClientHelper.py @@ -19,6 +19,7 @@ def substituteInLineCodes(value): value = value.replace( '%local_server_hostname%', urlparse(get_config('localBackendUrl')).netloc ) + value = value.replace('%home%', get_config('home_dir')) return value diff --git a/test/gui/shared/scripts/names.py b/test/gui/shared/scripts/names.py index 1e3349bc5b4..6a665381750 100644 --- a/test/gui/shared/scripts/names.py +++ b/test/gui/shared/scripts/names.py @@ -55,3 +55,4 @@ create_Remote_Folder_Enter_the_name_of_the_new_folder_to_be_created_below_QLabel = {"text": "Enter the name of the new folder to be created below '/':", "type": "QLabel", "unnamed": 1, "visible": 1, "window": create_Remote_Folder_QInputDialog} groupBox_folderTreeWidget_QTreeWidget = {"container": add_Folder_Sync_Connection_groupBox_QGroupBox, "name": "folderTreeWidget", "type": "QTreeWidget", "visible": 1} confirm_Folder_Sync_Connection_Removal_QMessageBox = {"type": "QMessageBox", "unnamed": 1, "visible": 1, "windowTitle": "Confirm Folder Sync Connection Removal"} +stackedWidget_quickWidget_OCC_QmlUtils_OCQuickWidget = {"container": stack_stackedWidget_QStackedWidget, "name": "quickWidget", "type": "OCC::QmlUtils::OCQuickWidget", "visible": 1} diff --git a/test/gui/shared/scripts/pageObjects/AccountConnectionWizard.py b/test/gui/shared/scripts/pageObjects/AccountConnectionWizard.py index e0966f94ce0..6a2e483ee97 100644 --- a/test/gui/shared/scripts/pageObjects/AccountConnectionWizard.py +++ b/test/gui/shared/scripts/pageObjects/AccountConnectionWizard.py @@ -350,3 +350,11 @@ def isVFSOptionChecked(): ).checked == True ) + + @staticmethod + def get_local_sync_path(): + return str( + squish.waitForObjectExists( + AccountConnectionWizard.SELECT_LOCAL_FOLDER + ).displayText + ) diff --git a/test/gui/shared/scripts/pageObjects/SyncConnectionWizard.py b/test/gui/shared/scripts/pageObjects/SyncConnectionWizard.py index 2ce6942d2c2..b9ac8ac1bef 100644 --- a/test/gui/shared/scripts/pageObjects/SyncConnectionWizard.py +++ b/test/gui/shared/scripts/pageObjects/SyncConnectionWizard.py @@ -113,6 +113,20 @@ class SyncConnectionWizard: "visible": 1, "window": names.add_Folder_Sync_Connection_OCC_FolderWizard, } + ADD_FOLDER_SYNC_BUTTON = { + "checkable": False, + "container": names.stackedWidget_quickWidget_OCC_QmlUtils_OCQuickWidget, + "id": "addSyncButton", + "type": "Button", + "unnamed": 1, + "visible": True, + } + WARN_LABEL = { + "window": names.add_Folder_Sync_Connection_OCC_FolderWizard, + "name": "warnLabel", + "type": "QLabel", + "visible": 1, + } @staticmethod def setSyncPathInSyncConnectionWizardOc10(sync_path=''): @@ -334,3 +348,30 @@ def has_remote_folder(folder_name): except: return False, None return True, parent_container + + @staticmethod + def is_remote_folder_selected(folder_selector): + return squish.waitForObjectExists(folder_selector).selected + + @staticmethod + def select_space_to_sync(space_name): + SyncConnectionWizard.selectSpaceToSync(space_name) + SyncConnectionWizard.nextStep() + + @staticmethod + def open_sync_connection_wizard(): + squish.mouseClick( + squish.waitForObject(SyncConnectionWizard.ADD_FOLDER_SYNC_BUTTON) + ) + + @staticmethod + def get_local_sync_path(): + return str( + squish.waitForObjectExists( + SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER + ).displayText + ) + + @staticmethod + def get_warn_label(): + return str(squish.waitForObjectExists(SyncConnectionWizard.WARN_LABEL).text) diff --git a/test/gui/shared/steps/account_context.py b/test/gui/shared/steps/account_context.py index 8ad6ff6fe7c..46e4e9839d8 100644 --- a/test/gui/shared/steps/account_context.py +++ b/test/gui/shared/steps/account_context.py @@ -17,7 +17,7 @@ from helpers.ConfigHelper import get_config, isWindows, isLinux -@When('the user adds the following wrong user credentials:') +@When('the user adds the following user credentials:') def step(context): account_details = getClientDetails(context) AccountConnectionWizard.addUserCreds( @@ -320,3 +320,34 @@ def step(context, displayname): has_focus = Toolbar.account_has_focus(account) if not has_focus: raise LookupError(f"Account '{displayname}' should be opened, but it is not") + + +@Then( + r'the default local sync path should contain "([^"]*)" in the (configuration|sync connection) wizard', + regexp=True, +) +def step(context, sync_path, wizard): + sync_path = substituteInLineCodes(sync_path) + + actual_sync_path = "" + if wizard == 'configuration': + actual_sync_path = AccountConnectionWizard.get_local_sync_path() + else: + actual_sync_path = SyncConnectionWizard.get_local_sync_path() + + test.compare( + actual_sync_path, + sync_path, + "Compare sync path contains the expected path", + ) + + +@Then('the warning "|any|" should appear in the sync connection wizard') +def step(context, warn_message): + actual_message = SyncConnectionWizard.get_warn_label() + contains_warning = True if warn_message in actual_message else False + test.compare( + True, + contains_warning, + "Contains warning message", + ) diff --git a/test/gui/shared/steps/file_context.py b/test/gui/shared/steps/file_context.py index 5e912eb003e..3bdf399419c 100644 --- a/test/gui/shared/steps/file_context.py +++ b/test/gui/shared/steps/file_context.py @@ -6,8 +6,6 @@ import shutil import zipfile -from pageObjects.AccountSetting import AccountSetting - from helpers.SetupClientHelper import getResourcePath, getTempResourcePath from helpers.SyncHelper import waitForClientToBeReady from helpers.ConfigHelper import get_config @@ -17,12 +15,9 @@ can_read, can_write, read_file_content, - is_empty_sync_folder, get_size_in_bytes, prefix_path_namespace, -) -from helpers.SetupClientHelper import ( - getTempResourcePath, + remember_path, ) @@ -370,3 +365,12 @@ def step(context, username, source): source_dir = getResourcePath(source, username) destination_dir = getTempResourcePath(source) shutil.copy2(source_dir, destination_dir) + + +@Given('the user has created folder "|any|" in the default home path') +def step(context, folder_name): + folder_path = join(get_config('home_dir'), folder_name) + os.makedirs(prefix_path_namespace(folder_path)) + remember_path(folder_path) + # when account is added, folder with suffix will be created + remember_path(folder_path + " (2)") diff --git a/test/gui/shared/steps/sync_context.py b/test/gui/shared/steps/sync_context.py index e5f840b6602..ce242f0c980 100644 --- a/test/gui/shared/steps/sync_context.py +++ b/test/gui/shared/steps/sync_context.py @@ -293,3 +293,13 @@ def step(context): @Then('the file "|any|" should have status "|any|" in the activity tab') def step(context, file_name, status): Activity.hasSyncStatus(file_name, status) + + +@When('the user selects the "|any|" space to sync') +def step(context, space_name): + SyncConnectionWizard.select_space_to_sync(space_name) + + +@When("the user opens the sync connection wizard") +def step(context): + SyncConnectionWizard.open_sync_connection_wizard() diff --git a/test/gui/tst_addAccount/test.feature b/test/gui/tst_addAccount/test.feature index 0541ee0b75f..4fb09973119 100644 --- a/test/gui/tst_addAccount/test.feature +++ b/test/gui/tst_addAccount/test.feature @@ -47,7 +47,7 @@ Feature: adding accounts Given the user has started the client And the user has entered the following account information: | server | %local_server% | - When the user adds the following wrong user credentials: + When the user adds the following user credentials: | user | Alice | | password | 12345 | Then the error "Invalid credentials" should be displayed in the account connection wizard @@ -81,3 +81,34 @@ Feature: adding accounts And the user syncs the "Personal" space Then the folder "simple-folder" should exist on the file system + @skipOnOCIS + Scenario: Check for incremented number in bracket while adding new account and folder (OC10) + Given the user has created folder "ownCloud" in the default home path + And the user has started the client + And the user has entered the following account information: + | server | %local_server% | + When the user adds the following user credentials: + | user | Alice | + | password | 1234 | + And the user opens the advanced configuration + Then the default local sync path should contain "%home%/ownCloud (2)" in the configuration wizard + When the user selects download everything option in advanced section + And the user opens the sync connection wizard + Then the default local sync path should contain "%home%/ownCloud (2) (2)" in the sync connection wizard + + @skipOnOC10 + Scenario: Check for incremented number in bracket while adding new account and folder (oCIS) + Given the user has created folder "ownCloud" in the default home path + And the user has started the client + And the user has entered the following account information: + | server | %local_server% | + When the user adds the following user credentials: + | user | Alice | + | password | 1234 | + And the user opens the advanced configuration + Then the default local sync path should contain "%home%/ownCloud (2)" in the configuration wizard + When the user selects download everything option in advanced section + And the user opens the sync connection wizard + And the user selects the "Personal" space to sync + Then the default local sync path should contain "%home%/ownCloud (2)/Personal" in the sync connection wizard + And the warning "There is already a sync from the server to this local folder. Please pick another local folder!" should appear in the sync connection wizard