Skip to content

Commit

Permalink
combine common steps using regex
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Oct 25, 2021
1 parent 025e8c1 commit c3c304f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 71 deletions.
3 changes: 0 additions & 3 deletions test/gui/shared/scripts/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@
choose_What_to_Sync_OCC_SelectiveSyncDialog = {"type": "OCC::SelectiveSyncDialog", "unnamed": 1, "visible": 1, "windowTitle": "Choose What to Sync"}
choose_What_to_Sync_Deselect_remote_folders_you_do_not_wish_to_synchronize_QLabel = {"text": "Deselect remote folders you do not wish to synchronize.", "type": "QLabel", "unnamed": 1, "visible": 1, "window": choose_What_to_Sync_OCC_SelectiveSyncDialog}
choose_What_To_Synchronize_QTreeWidget = {"aboveWidget": choose_What_to_Sync_Deselect_remote_folders_you_do_not_wish_to_synchronize_QLabel, "type": "QTreeWidget", "unnamed": 1, "visible": 1, "window": choose_What_to_Sync_OCC_SelectiveSyncDialog}
deselect_remote_folders_you_do_not_wish_to_synchronize_QModelIndex = {"column": 0, "container": choose_What_To_Synchronize_QTreeWidget, "text": "/", "type": "QModelIndex"}
owncloudWizard_OwncloudHttpCredsPage_OCC_OwncloudHttpCredsPage = {"name": "OwncloudHttpCredsPage", "type": "OCC::OwncloudHttpCredsPage", "visible": 1, "window": owncloudWizard_OCC_OwncloudWizard}
owncloudWizard_OwncloudAdvancedSetupPage_OCC_OwncloudAdvancedSetupPage = {"name": "OwncloudAdvancedSetupPage", "type": "OCC::OwncloudAdvancedSetupPage", "visible": 1, "window": owncloudWizard_OCC_OwncloudWizard}
deselect_remote_folders_you_do_not_wish_to_synchronize_QHeaderView = {"container": choose_What_To_Synchronize_QTreeWidget, "orientation": 1, "type": "QHeaderView", "unnamed": 1, "visible": 1}
name_HeaderViewItem = {"container": deselect_remote_folders_you_do_not_wish_to_synchronize_QHeaderView, "text": "Name", "type": "HeaderViewItem", "visible": True}
size_HeaderViewItem = {"container": deselect_remote_folders_you_do_not_wish_to_synchronize_QHeaderView, "text": "Size", "type": "HeaderViewItem", "visible": True}
53 changes: 38 additions & 15 deletions test/gui/shared/scripts/pageObjects/AccountConnectionWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,38 @@ class AccountConnectionWizard:
"visible": 1,
"window": names.owncloudWizard_OCC_OwncloudWizard,
}
CREDENTIAL_PAGE = (
names.owncloudWizard_OwncloudHttpCredsPage_OCC_OwncloudHttpCredsPage
)
ADVANCE_SETUP_PAGE = (
names.owncloudWizard_OwncloudAdvancedSetupPage_OCC_OwncloudAdvancedSetupPage
)
MANUAL_SYNC_FOLDER_OPTION = {
"name": "rManualFolder",
"type": "QRadioButton",
"visible": 1,
"window": names.owncloudWizard_OCC_OwncloudWizard,
}
CHOOSE_WHAT_TO_SYNC_BUTTON = {
"name": "bSelectiveSync",
"type": "QPushButton",
"visible": 1,
"window": names.owncloudWizard_OCC_OwncloudWizard,
}

CHOOSE_WHAT_TO_SYNC_CHECKBOX = names.choose_What_To_Synchronize_QTreeWidget
CHOOSE_WHAT_TO_SYNC_OK_BUTTON = {
SELECTIVE_SYNC_DIALOG = names.choose_What_to_Sync_OCC_SelectiveSyncDialog
SYNC_DIALOG_FOLDER_TREE = names.choose_What_To_Synchronize_QTreeWidget
SYNC_DIALOG_ROOT_FOLDER = {
"column": 0,
"container": SYNC_DIALOG_FOLDER_TREE,
"text": "/",
"type": "QModelIndex",
}
SYNC_DIALOG_OK_BUTTON = {
"text": "OK",
"type": "QPushButton",
"unnamed": 1,
"visible": 1,
"window": names.choose_What_to_Sync_OCC_SelectiveSyncDialog,
}
MANUAL_SYNC_FOLDER_OPTION = {
"name": "rManualFolder",
"type": "QRadioButton",
"visible": 1,
"window": names.owncloudWizard_OCC_OwncloudWizard,
"window": SELECTIVE_SYNC_DIALOG,
}

def __init__(self):
Expand Down Expand Up @@ -110,21 +122,32 @@ def selectManualSyncFolder(self):
def selectFoldersToSync(self, context):
self.openSyncDialog()

# first deselect all
squish.mouseClick(
squish.waitForObjectItem(self.CHOOSE_WHAT_TO_SYNC_CHECKBOX, "/"),
squish.waitForObject(self.SYNC_DIALOG_ROOT_FOLDER),
11,
11,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
for row in context.table[1:]:
squish.mouseClick(
squish.waitForObjectItem(
self.CHOOSE_WHAT_TO_SYNC_CHECKBOX, "/." + row[0]
),
squish.waitForObjectItem(self.SYNC_DIALOG_FOLDER_TREE, "/." + row[0]),
11,
11,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
squish.clickButton(squish.waitForObject(self.CHOOSE_WHAT_TO_SYNC_OK_BUTTON))
squish.clickButton(squish.waitForObject(self.SYNC_DIALOG_OK_BUTTON))

def sortBy(self, headerText):
squish.mouseClick(
squish.waitForObject(
{
"container": names.deselect_remote_folders_you_do_not_wish_to_synchronize_QHeaderView,
"text": headerText,
"type": "HeaderViewItem",
"visible": True,
}
)
)
102 changes: 52 additions & 50 deletions test/gui/shared/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ def waitForFolderToBeSynced(context, folderName):
)


def doFolderExist(folderPath, timeout=1000):
def folderExists(folderPath, timeout=1000):
return waitFor(
lambda: isdir(sanitizePath(folderPath)),
timeout,
)


def doFileExist(filePath, timeout=1000):
def fileExists(filePath, timeout=1000):
return waitFor(
lambda: isfile(sanitizePath(filePath)),
timeout,
Expand Down Expand Up @@ -351,38 +351,44 @@ def step(context, filePath):
)


@Then('the file "|any|" should exist on the file system')
def step(context, file):
filePath = join(context.userData['clientSyncPathUser1'], file)
fileExists = doFileExist(filePath, context.userData['clientSyncTimeout'] * 1000)

test.compare(True, fileExists)


@Then('the file "|any|" should not exist on the file system')
def step(context, file):
filePath = join(context.userData['clientSyncPathUser1'], file)
fileExists = doFileExist(filePath)

test.compare(False, fileExists)

@Then(r'^the (file|folder) "([^"]*)" should exist on the file system$', regexp=True)
def step(context, resourceType, resource):
resourcePath = join(context.userData['clientSyncPathUser1'], resource)
resourceExists = False
if resourceType == 'file':
resourceExists = fileExists(
resourcePath, context.userData['clientSyncTimeout'] * 1000
)
elif resourceType == 'folder':
resourceExists = folderExists(
resourcePath, context.userData['clientSyncTimeout'] * 1000
)
else:
raise Exception("Unsupported resource type '" + resourceType + "'")

@Then('the folder "|any|" should exist on the file system')
def step(context, folder):
folderPath = join(context.userData['clientSyncPathUser1'], folder)
folderExists = doFolderExist(
folderPath, context.userData['clientSyncTimeout'] * 1000
test.compare(
True,
resourceExists,
"Assert " + resourceType + " '" + resource + "' exists on the system",
)

test.compare(True, folderExists)

@Then(r'^the (file|folder) "([^"]*)" should not exist on the file system$', regexp=True)
def step(context, resourceType, resource):
resourcePath = join(context.userData['clientSyncPathUser1'], resource)
resourceExists = False
if resourceType == 'file':
resourceExists = fileExists(resourcePath, 1000)
elif resourceType == 'folder':
resourceExists = folderExists(resourcePath, 1000)
else:
raise Exception("Unsupported resource type '" + resourceType + "'")

@Then('the folder "|any|" should not exist on the file system')
def step(context, folder):
folderPath = join(context.userData['clientSyncPathUser1'], folder)
folderExists = doFolderExist(folderPath)

test.compare(False, folderExists)
test.compare(
False,
resourceExists,
"Assert " + resourceType + " '" + resource + "' doesn't exist on the system",
)


@Given('the user has paused the file sync')
Expand Down Expand Up @@ -905,9 +911,7 @@ def step(context):
newAccount = AccountConnectionWizard()
newAccount.addServer(context)
test.compare(
waitForObjectExists(
names.owncloudWizard_OwncloudHttpCredsPage_OCC_OwncloudHttpCredsPage
).visible,
waitForObjectExists(newAccount.CREDENTIAL_PAGE).visible,
True,
"Assert credentials page is visible",
)
Expand All @@ -924,9 +928,7 @@ def step(context):
newAccount = AccountConnectionWizard()
newAccount.addUserCreds(context)
test.compare(
waitForObjectExists(
names.owncloudWizard_OwncloudAdvancedSetupPage_OCC_OwncloudAdvancedSetupPage
).visible,
waitForObjectExists(newAccount.ADVANCE_SETUP_PAGE).visible,
True,
"Assert setup page is visible",
)
Expand All @@ -942,9 +944,8 @@ def step(context):
def step(context):
newAccount = AccountConnectionWizard()
newAccount.openSyncDialog()

test.compare(
waitForObjectExists(names.choose_What_to_Sync_OCC_SelectiveSyncDialog).visible,
waitForObjectExists(newAccount.SELECTIVE_SYNC_DIALOG).visible,
True,
"Assert selective sync dialog is visible",
)
Expand Down Expand Up @@ -974,43 +975,44 @@ def step(context):
newAccount.connectAccount()


@When("the user sorts the folder list by name")
def step(context):
mouseClick(waitForObject(names.name_HeaderViewItem))


@When("the user sorts the folder list by size")
def step(context):
mouseClick(waitForObject(names.size_HeaderViewItem))
@When('the user sorts the folder list by "|any|"')
def step(context, headerText):
headerText = headerText.capitalize()
if headerText in ["Size", "Name"]:
newAccount = AccountConnectionWizard()
newAccount.sortBy(headerText)
else:
raise Exception("Sorting by '" + headerText + "' is not supported.")


@Then('the dialog chose_what_to_sync should be visible')
def step(context):
newAccount = AccountConnectionWizard()
test.compare(
waitForObjectExists(names.choose_What_to_Sync_OCC_SelectiveSyncDialog).visible,
waitForObjectExists(newAccount.SELECTIVE_SYNC_DIALOG).visible,
True,
"Assert selective sync dialog is visible",
)


@Then('the sync all checkbox should be checked')
def step(context):
newAccount = AccountConnectionWizard()
test.compare(
waitForObjectExists(
names.deselect_remote_folders_you_do_not_wish_to_synchronize_QModelIndex
).checkState,
waitForObjectExists(newAccount.SYNC_DIALOG_ROOT_FOLDER).checkState,
"checked",
"Assert sync all checkbox is checked",
)


@Then("the folders should be in the following order:")
def step(context):
newAccount = AccountConnectionWizard()
rowIndex = 0
for row in context.table[1:]:
FOLDER_TREE_ROW = {
"row": rowIndex,
"container": names.deselect_remote_folders_you_do_not_wish_to_synchronize_QModelIndex,
"container": newAccount.SYNC_DIALOG_ROOT_FOLDER,
"type": "QModelIndex",
}
expectedFolder = row[0]
Expand Down
6 changes: 3 additions & 3 deletions test/gui/tst_syncing/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ Feature: Syncing files
| aFolder |
| bFolder |
# sort folder by name in descending order
When the user sorts the folder list by name
When the user sorts the folder list by "Name"
Then the folders should be in the following order:
| folder |
| bFolder |
| aFolder |
| 123Folder |
# sort folder by size in ascending order
When the user sorts the folder list by size
When the user sorts the folder list by "Size"
Then the folders should be in the following order:
| folder |
| bFolder |
| 123Folder |
| aFolder |
# sort folder by size in descending order
When the user sorts the folder list by size
When the user sorts the folder list by "Size"
Then the folders should be in the following order:
| folder |
| aFolder |
Expand Down

0 comments on commit c3c304f

Please sign in to comment.