From 4478fd29d4e4ff7ba1a2330f5fa742800f1d728e Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Tue, 7 Nov 2023 16:52:14 +0545 Subject: [PATCH] properly wait for AUT context to get removed --- test/gui/shared/scripts/bdd_hooks.py | 25 ++---------------- .../scripts/helpers/SetupClientHelper.py | 25 ++++++++++++++++-- test/gui/shared/scripts/names.py | 1 - .../scripts/pageObjects/AccountSetting.py | 25 +++++++++++++++++- .../gui/shared/scripts/pageObjects/Toolbar.py | 18 ++++++++++--- test/gui/shared/steps/account_context.py | 26 ++++++------------- test/gui/tst_loginLogout/test.feature | 19 +++++--------- 7 files changed, 77 insertions(+), 62 deletions(-) diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index 7cc0291270d..a68ff9d83fd 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -21,6 +21,7 @@ from helpers.StacktraceHelper import getCoredumps, generateStacktrace from helpers.SyncHelper import closeSocketConnection, clearWaitedAfterSync from helpers.SpaceHelper import delete_project_spaces +from helpers.SetupClientHelper import wait_until_app_killed from helpers.ConfigHelper import ( init_config, get_config, @@ -116,27 +117,6 @@ def scenarioFailed(): ) -def isAppKilled(pid): - if os.path.isdir('/proc/{}'.format(pid)): - # process is still running - # wait 100ms before checking again - snooze(0.1) - return False - return True - - -def waitUntilAppIsKilled(pid=0): - timeout = get_config('minSyncTimeout') * 1000 - killed = waitFor( - lambda: isAppKilled(pid), - timeout, - ) - if not killed: - test.log( - "Application was not terminated within {} milliseconds".format(timeout) - ) - - # runs after every scenario # Order: 1 # cleanup spaces @@ -157,7 +137,6 @@ def hook(context): # capture a screenshot if there is error or test failure in the current scenario execution if scenarioFailed() and os.getenv('CI'): - import gi gi.require_version('Gtk', '3.0') @@ -183,7 +162,7 @@ def hook(context): # get pid before detaching pid = ctx.pid ctx.detach() - waitUntilAppIsKilled(pid) + wait_until_app_killed(pid) # delete local files/folders for filename in os.listdir(get_config('clientRootSyncPath')): diff --git a/test/gui/shared/scripts/helpers/SetupClientHelper.py b/test/gui/shared/scripts/helpers/SetupClientHelper.py index 7d2a45e5195..56c78da285c 100644 --- a/test/gui/shared/scripts/helpers/SetupClientHelper.py +++ b/test/gui/shared/scripts/helpers/SetupClientHelper.py @@ -1,6 +1,6 @@ from urllib.parse import urlparse -import squish -from os import makedirs +import squish, test +from os import makedirs, path from os.path import exists, join from helpers.SpaceHelper import get_space_id from helpers.ConfigHelper import get_config, set_config @@ -152,3 +152,24 @@ def setUpClient(username, displayName, space="Personal"): startClient() listenSyncStatusForItem(syncPath) + + +def is_app_killed(pid): + if path.isdir('/proc/{}'.format(pid)): + # process is still running + # wait 100ms before checking again + squish.snooze(0.1) + return False + return True + + +def wait_until_app_killed(pid=0): + timeout = 5 * 1000 + killed = squish.waitFor( + lambda: is_app_killed(pid), + timeout, + ) + if not killed: + test.log( + "Application was not terminated within {} milliseconds".format(timeout) + ) diff --git a/test/gui/shared/scripts/names.py b/test/gui/shared/scripts/names.py index f2184da5a04..b42141e74ec 100644 --- a/test/gui/shared/scripts/names.py +++ b/test/gui/shared/scripts/names.py @@ -50,4 +50,3 @@ o_folderList_Personal_QModelIndex = {"column": 0, "container": stack_folderList_QTreeView, "text": "Personal", "type": "QModelIndex"} add_Folder_Sync_Connection_tableView_QTableView = {"name": "tableView","type": "QTableView","visible": 1,"window": add_Folder_Sync_Connection_OCC_FolderWizard} stack_scrollArea_QScrollArea = {"container": settings_stack_QStackedWidget, "name": "scrollArea", "type": "QScrollArea", "visible": 1} -quit_ownCloud_QMessageBox = {"type": "QMessageBox", "unnamed": 1, "visible": 1, "windowTitle": "Quit ownCloud"} diff --git a/test/gui/shared/scripts/pageObjects/AccountSetting.py b/test/gui/shared/scripts/pageObjects/AccountSetting.py index dc971074a25..550937d1781 100644 --- a/test/gui/shared/scripts/pageObjects/AccountSetting.py +++ b/test/gui/shared/scripts/pageObjects/AccountSetting.py @@ -52,6 +52,12 @@ class AccountSetting: "type": "OCC::LoginRequiredDialog", "visible": 1, } + ACCOUNT_LOADING = { + "window": names.settings_OCC_SettingsDialog, + "name": "loadingPage", + "type": "QWidget", + "visible": 0, + } @staticmethod def accountAction(action): @@ -136,13 +142,30 @@ def waitUntilAccountIsConnected(displayname, server, timeout=5000): ) if not result: - raise Exception( + raise TimeoutError( "Timeout waiting for the account to be connected for " + str(timeout) + " milliseconds" ) return result + @staticmethod + def wait_until_sync_folder_is_configured(timeout=5000): + result = squish.waitFor( + lambda: not squish.waitForObjectExists( + AccountSetting.ACCOUNT_LOADING + ).visible, + timeout, + ) + + if not result: + raise TimeoutError( + "Timeout waiting for sync folder to be connected for " + + str(timeout) + + " milliseconds" + ) + return result + @staticmethod def confirmRemoveAllFiles(): squish.clickButton(squish.waitForObject(AccountSetting.REMOVE_ALL_FILES)) diff --git a/test/gui/shared/scripts/pageObjects/Toolbar.py b/test/gui/shared/scripts/pageObjects/Toolbar.py index 51d0f67a046..32cb8f9514c 100644 --- a/test/gui/shared/scripts/pageObjects/Toolbar.py +++ b/test/gui/shared/scripts/pageObjects/Toolbar.py @@ -1,14 +1,20 @@ import squish -import names +from helpers.SetupClientHelper import wait_until_app_killed class Toolbar: - QUIT_OWNCLOUD_YES_QPUSHBUTTON = { + QUIT_CONFIRMATION_DIALOG = { + "type": "QMessageBox", + "unnamed": 1, + "visible": 1, + "windowTitle": "Quit ownCloud", + } + CONFIRM_QUIT_BUTTON = { "text": "Yes", "type": "QPushButton", "unnamed": 1, "visible": 1, - "window": names.quit_ownCloud_QMessageBox, + "window": QUIT_CONFIRMATION_DIALOG, } @staticmethod @@ -50,4 +56,8 @@ def quitOwncloud(): squish.clickButton( squish.waitForObject(Toolbar.getItemSelector("Quit ownCloud")) ) - squish.clickButton(squish.waitForObject(Toolbar.QUIT_OWNCLOUD_YES_QPUSHBUTTON)) + squish.clickButton(squish.waitForObject(Toolbar.CONFIRM_QUIT_BUTTON)) + for ctx in squish.applicationContextList(): + pid = ctx.pid + ctx.detach() + wait_until_app_killed(pid) diff --git a/test/gui/shared/steps/account_context.py b/test/gui/shared/steps/account_context.py index 1b00d3c4d9c..05f45126eea 100644 --- a/test/gui/shared/steps/account_context.py +++ b/test/gui/shared/steps/account_context.py @@ -65,6 +65,11 @@ def step(context): startClient() +@When('the user starts the client') +def step(context): + startClient() + + @When('the user opens the add-account dialog') def step(context): Toolbar.openNewAccountSetup() @@ -76,12 +81,6 @@ def step(context): AccountConnectionWizard.addAccount(account_details) -@When('the user starts the client') -def step(context): - squish.snooze(2) - startClient() - - @When(r'^the user adds (the first|another) account with$', regexp=True) def step(context, accountType): if accountType == 'another': @@ -148,11 +147,8 @@ def step(context, username, password): def step(context, username): displayname = getDisplaynameForUser(username) server = get_config('localBackendUrl') - test.compare( - AccountSetting.waitUntilAccountIsConnected(displayname, server), - True, - "User '%s' is connected" % username, - ) + AccountSetting.waitUntilAccountIsConnected(displayname, server) + AccountSetting.wait_until_sync_folder_is_configured() @When('the user removes the connection for user "|any|" and host |any|') @@ -247,12 +243,6 @@ def step(context): test.compare(True, AccountSetting.isLogDialogVisible(), "Log dialog is opened") -@Given('the user has added the following account with oauth2 enabled:') -def step(context): - AccountConnectionWizard.addAccountWithOauth2(context) - # squish.snooze(1) - - @When('the user adds the following account with oauth2 enabled:') def step(context): AccountConnectionWizard.addAccountWithOauth2(context) @@ -284,6 +274,6 @@ def step(context, username): raise Exception("oidc re-login failed") -@Given("the user has quitted the client") +@When("the user quits the client") def step(context): Toolbar.quitOwncloud() diff --git a/test/gui/tst_loginLogout/test.feature b/test/gui/tst_loginLogout/test.feature index 6c54021c97c..563044e9254 100644 --- a/test/gui/tst_loginLogout/test.feature +++ b/test/gui/tst_loginLogout/test.feature @@ -43,22 +43,15 @@ Feature: Logout users Scenario: login after loggin out with oauth2 enabled Given app "oauth2" has been "enabled" in the server And the user has started the client - And the user has added the following account with oauth2 enabled: + When the user adds the following account with oauth2 enabled: | server | %local_server% | | user | Alice | | password | 1234 | - And the user "Alice" has logged out of the client-UI + Then user "Alice" should be connect to the client-UI + When the user "Alice" logs out of the client-UI + Then user "Alice" should be signed out When user "Alice" logs in with oauth2 to the client-UI Then user "Alice" should be connect to the client-UI - - @skipOnOCIS - Scenario: the client re-auths after restarting - Given app "oauth2" has been "enabled" in the server - And the user has started the client - And the user has added the following account with oauth2 enabled: - | server | %local_server% | - | user | Alice | - | password | 1234 | - And the user has quitted the client - When the user starts the client + When the user quits the client + And the user starts the client Then user "Alice" should be connect to the client-UI