Skip to content

Commit

Permalink
[gui-tests][full-ci] Cleanup account from UI after each test (#11436)
Browse files Browse the repository at this point in the history
* cleanup account from UI after each test

* close all opened dailogs

* do not check account dialog if no accounts are setup

* fix python format

* use proper methods

* fix closing dialogs
  • Loading branch information
saw-jan authored Dec 20, 2023
1 parent 25f12c6 commit fc921b2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 24 deletions.
81 changes: 59 additions & 22 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import shutil
import urllib.request
import os
from urllib.parse import urlparse
from helpers.StacktraceHelper import getCoredumps, generateStacktrace
from helpers.SyncHelper import closeSocketConnection, clearWaitedAfterSync
from helpers.SpaceHelper import delete_project_spaces
Expand All @@ -32,6 +33,9 @@
)
from helpers.api.utils import url_join
from datetime import datetime
from pageObjects.Toolbar import Toolbar
from pageObjects.AccountSetting import AccountSetting
from pageObjects.AccountConnectionWizard import AccountConnectionWizard

# this will reset in every test suite
previousFailResultCount = 0
Expand Down Expand Up @@ -166,28 +170,8 @@ def hook(context):

pb.savev(os.path.join(directory, filename), "png", [], [])

# Detach (i.e. potentially terminate) all AUTs at the end of a scenario
for ctx in applicationContextList():
# get pid before detaching
pid = ctx.pid
ctx.detach()
wait_until_app_killed(pid)

# clean up config files
for config_file in os.listdir(get_config('clientConfigDir')):
os.unlink(os.path.join(get_config('clientConfigDir'), config_file))

# delete local files/folders
for filename in os.listdir(get_config('clientRootSyncPath')):
test.log("Deleting: " + filename)
file_path = os.path.join(get_config('clientRootSyncPath'), filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
test.log(f'Failed to delete{file_path}. Reason: {e}.')
# teardown accounts and configs
teardown_client()

# search coredumps after every test scenario
# CI pipeline might fail although all tests are passing
Expand Down Expand Up @@ -216,3 +200,56 @@ def hook(context):

previousFailResultCount = test.resultCount("fails")
previousErrorResultCount = test.resultCount("errors")


def teardown_client():
# Cleanup user accounts from UI for Windows platform
# It is not needed for Linux so skipping it in order to save CI time
if isWindows():
# remove account from UI
# In Windows, removing only config and sync folders won't help
# so to work around that, remove the account connection
close_open_dialogs()
server_host = urlparse(get_config('localBackendUrl')).netloc
accounts = Toolbar.get_accounts()
for account in accounts:
displayname = account.split('\n')[0]
Toolbar.openAccount(displayname, server_host)
AccountSetting.removeAccountConnection()
if accounts:
waitForObject(AccountConnectionWizard.SERVER_ADDRESS_BOX)

# Detach (i.e. potentially terminate) all AUTs at the end of a scenario
for ctx in applicationContextList():
# get pid before detaching
pid = ctx.pid
ctx.detach()
wait_until_app_killed(pid)

# clean up config files
shutil.rmtree(get_config('clientConfigDir'))

# delete test files/folders
for entry in os.scandir(get_config('clientRootSyncPath')):
test.log("Deleting: " + entry.name)
try:
if entry.is_file() or entry.is_symlink():
os.unlink(entry.path)
elif entry.is_dir():
shutil.rmtree(entry.path)
except Exception as e:
test.log(f'Failed to delete{entry.name}. Reason: {e}.')


def close_open_dialogs():
# close the current active dailog if it's not a main client window
while True:
active_window = QApplication.activeModalWidget()
if str(active_window) == "<null>":
break
test.log(f"Closing '{active_window.objectName}' window")
closed = active_window.close()
if not closed:
confirm_dialog = QApplication.activeModalWidget()
if confirm_dialog.visible:
clickButton(waitForObject(AccountSetting.CONFIRMATION_YES_BUTTON))
1 change: 1 addition & 0 deletions test/gui/shared/scripts/pageObjects/AccountSetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AccountSetting:
"type": "QWidget",
"visible": 0,
}
CONFIRMATION_YES_BUTTON = {"text": "Yes", "type": "QPushButton", "visible": 1}

@staticmethod
def accountAction(action):
Expand Down
1 change: 0 additions & 1 deletion test/gui/shared/scripts/pageObjects/SharingDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class SharingDialog:

ITEM_TO_SHARE = {
"name": "label_name",
"type": "QLabel",
Expand Down
22 changes: 21 additions & 1 deletion test/gui/shared/scripts/pageObjects/Toolbar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import squish
import squish, object, names
from helpers.SetupClientHelper import wait_until_app_killed


class Toolbar:
TOOLBAR = {
"name": "toolBar",
"type": "QToolBar",
"visible": 1,
"window": names.settings_OCC_SettingsDialog,
}
QUIT_CONFIRMATION_DIALOG = {
"type": "QMessageBox",
"unnamed": 1,
Expand All @@ -17,6 +23,8 @@ class Toolbar:
"window": QUIT_CONFIRMATION_DIALOG,
}

TOOLBAR_ITEMS = ["Add account", "Activity", "Settings", "Quit ownCloud"]

@staticmethod
def getItemSelector(item_name):
return {
Expand Down Expand Up @@ -61,3 +69,15 @@ def quit_owncloud():
pid = ctx.pid
ctx.detach()
wait_until_app_killed(pid)

@staticmethod
def get_accounts():
accounts = []
children_obj = object.children(squish.waitForObject(Toolbar.TOOLBAR))
for obj in children_obj:
if hasattr(obj, "objectName") and str(obj.objectName).startswith(
"settingsdialog_toolbutton"
):
if not obj.text in Toolbar.TOOLBAR_ITEMS:
accounts.append(str(obj.text))
return accounts

0 comments on commit fc921b2

Please sign in to comment.