-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
202 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,115 @@ | ||
import names | ||
import squish | ||
from helpers.WebUIHelper import authorize_via_webui | ||
from helpers.ConfigHelper import get_config | ||
from pageObjects.AccountConnectionWizard import AccountConnectionWizard | ||
from helpers.UserHelper import getPasswordForUser | ||
|
||
|
||
class EnterPassword: | ||
LOGIN_DIALOG = { | ||
"name": "LoginRequiredDialog", | ||
"type": "OCC::LoginRequiredDialog", | ||
"visible": 1, | ||
} | ||
LOGIN_USER_LABEL = { | ||
"name": "topLabel", | ||
"type": "QLabel", | ||
"visible": 1, | ||
"window": LOGIN_DIALOG, | ||
} | ||
USERNAME_BOX = { | ||
"name": "usernameLineEdit", | ||
"type": "QLineEdit", | ||
"visible": 1, | ||
"window": LOGIN_DIALOG, | ||
} | ||
PASSWORD_BOX = { | ||
"container": names.loginRequiredDialog_contentWidget_QStackedWidget, | ||
"name": "passwordLineEdit", | ||
"type": "QLineEdit", | ||
"visible": 1, | ||
"window": LOGIN_DIALOG, | ||
} | ||
LOGIN_BUTTON = { | ||
"text": "Log in", | ||
"type": "QPushButton", | ||
"visible": 1, | ||
"window": names.stack_stackedWidget_QStackedWidget, | ||
"window": LOGIN_DIALOG, | ||
} | ||
LOGOUT_BUTTON = { | ||
"text": "Log out", | ||
"type": "QPushButton", | ||
"visible": 1, | ||
"window": names.stack_stackedWidget_QStackedWidget, | ||
"window": LOGIN_DIALOG, | ||
} | ||
COPY_URL_TO_CLIPBOARD_BUTTON = { | ||
"container": names.loginRequiredDialog_contentWidget_QStackedWidget, | ||
"name": "copyUrlToClipboardButton", | ||
"type": "QPushButton", | ||
"visible": 1, | ||
"window": LOGIN_DIALOG, | ||
} | ||
TLS_CERT_WINDOW = { | ||
"name": "OCC__TlsErrorDialog", | ||
"type": "OCC::TlsErrorDialog", | ||
"visible": 1, | ||
} | ||
ACCEPT_CERTIFICATE_YES = { | ||
"text": "Yes", | ||
"type": "QPushButton", | ||
"visible": 1, | ||
"window": TLS_CERT_WINDOW, | ||
} | ||
|
||
@staticmethod | ||
def enterPassword(password): | ||
squish.waitForObject( | ||
EnterPassword.PASSWORD_BOX, get_config('maxSyncTimeout') * 1000 | ||
) | ||
squish.type(squish.waitForObject(EnterPassword.PASSWORD_BOX), password) | ||
squish.clickButton(squish.waitForObject(EnterPassword.LOGIN_BUTTON)) | ||
def __init__(self, occurrence=1): | ||
if occurrence > 1 and not get_config('ocis'): | ||
self.LOGIN_DIALOG.update({"occurrence": occurrence}) | ||
elif occurrence > 1 and get_config('ocis'): | ||
self.TLS_CERT_WINDOW.update({"occurrence": occurrence}) | ||
|
||
@staticmethod | ||
def oidcReLogin(username, password): | ||
def get_username(self): | ||
# Parse username from following label: | ||
# Please enter your password to log in to the account Alice Hansen@localhost. | ||
# The account Alice Hansen@localhost:9200 is currently logged out. | ||
label = str(squish.waitForObjectExists(self.LOGIN_USER_LABEL).text) | ||
label = label.split("@", maxsplit=1)[0].split(" ") | ||
label.reverse() | ||
return label[1].capitalize() | ||
|
||
def enterPassword(self, password): | ||
squish.waitForObject(self.PASSWORD_BOX, get_config('maxSyncTimeout') * 1000) | ||
squish.type(squish.waitForObject(self.PASSWORD_BOX), password) | ||
squish.clickButton(squish.waitForObject(self.LOGIN_BUTTON)) | ||
|
||
def oidcReLogin(self, username, password): | ||
# wait 500ms for copy button to fully load | ||
squish.snooze(1 / 2) | ||
squish.clickButton( | ||
squish.waitForObject(EnterPassword.COPY_URL_TO_CLIPBOARD_BUTTON) | ||
) | ||
squish.clickButton(squish.waitForObject(self.COPY_URL_TO_CLIPBOARD_BUTTON)) | ||
authorize_via_webui(username, password) | ||
|
||
@staticmethod | ||
def oauthReLogin(username, password): | ||
def oauthReLogin(self, username, password): | ||
# wait 500ms for copy button to fully load | ||
squish.snooze(1 / 2) | ||
squish.clickButton( | ||
squish.waitForObject(EnterPassword.COPY_URL_TO_CLIPBOARD_BUTTON) | ||
) | ||
squish.clickButton(squish.waitForObject(self.COPY_URL_TO_CLIPBOARD_BUTTON)) | ||
authorize_via_webui(username, password, "oauth") | ||
|
||
@staticmethod | ||
def reLogin(username, password, oauth=False): | ||
def reLogin(self, username, password, oauth=False): | ||
if get_config('ocis'): | ||
EnterPassword.oidcReLogin(username, password) | ||
self.oidcReLogin(username, password) | ||
elif oauth: | ||
EnterPassword.oauthReLogin(username, password) | ||
self.oauthReLogin(username, password) | ||
else: | ||
EnterPassword.enterPassword(password) | ||
self.enterPassword(password) | ||
|
||
def loginAfterSetup(self, username=None, password=None): | ||
if not username: | ||
username = self.get_username() | ||
password = getPasswordForUser(username) | ||
|
||
@staticmethod | ||
def loginAfterSetup(username, password): | ||
if get_config('ocis'): | ||
AccountConnectionWizard.acceptCertificate() | ||
EnterPassword.oidcReLogin(username, password) | ||
self.oidcReLogin(username, password) | ||
else: | ||
EnterPassword.enterPassword(password) | ||
self.enterPassword(password) | ||
|
||
def logout(self): | ||
squish.clickButton(squish.waitForObject(self.LOGOUT_BUTTON)) | ||
|
||
@staticmethod | ||
def logout(): | ||
squish.clickButton(squish.waitForObject(EnterPassword.LOGOUT_BUTTON)) | ||
def accept_certificate(self): | ||
squish.clickButton(squish.waitForObject(self.ACCEPT_CERTIFICATE_YES)) |
Oops, something went wrong.