2023-07-24 18:25:36 +03:00
|
|
|
from selenium.common.exceptions import NoSuchElementException
|
|
|
|
|
2024-12-30 21:10:54 +01:00
|
|
|
from tests import common_password
|
2021-01-25 17:35:40 +01:00
|
|
|
from views.base_element import Button, EditBox, Text
|
2018-01-03 11:34:40 +02:00
|
|
|
from views.base_view import BaseView
|
2023-07-24 18:25:36 +03:00
|
|
|
|
2021-11-18 16:16:48 +01:00
|
|
|
|
2021-01-25 17:35:40 +01:00
|
|
|
class MultiAccountButton(Button):
|
|
|
|
class Username(Text):
|
2019-07-23 02:19:30 +03:00
|
|
|
def __init__(self, driver, locator_value):
|
2024-06-07 21:21:29 +03:00
|
|
|
super(MultiAccountButton.Username, self).__init__(
|
|
|
|
driver,
|
|
|
|
xpath="%s//android.widget.TextView[@content-desc='username']" % locator_value)
|
2021-11-18 16:16:48 +01:00
|
|
|
|
2020-01-29 10:29:56 +03:00
|
|
|
def __init__(self, driver, position=1):
|
2021-01-25 17:35:40 +01:00
|
|
|
super(MultiAccountButton, self).__init__(driver,
|
|
|
|
xpath="//*[@content-desc='select-account-button-%s']" % position)
|
|
|
|
self.username = self.Username(driver, self.locator)
|
2017-09-21 20:01:04 +03:00
|
|
|
|
|
|
|
|
2021-01-25 17:35:40 +01:00
|
|
|
class MultiAccountOnLoginButton(Button):
|
2020-01-29 10:29:56 +03:00
|
|
|
def __init__(self, driver, position=1):
|
2021-01-25 17:35:40 +01:00
|
|
|
super(MultiAccountOnLoginButton, self).__init__(driver,
|
|
|
|
xpath="(//*[@content-desc='chat-icon'])[%s]/.." % position)
|
2020-01-29 10:29:56 +03:00
|
|
|
|
2021-03-04 11:35:48 +02:00
|
|
|
@property
|
|
|
|
def account_logo(self):
|
|
|
|
class AccountLogo(Text):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, xpath="%s//*[@content-desc='chat-icon']" % parent_locator)
|
|
|
|
|
|
|
|
return AccountLogo(self.driver, self.locator)
|
|
|
|
|
|
|
|
|
2023-03-21 08:38:42 +02:00
|
|
|
class LogInButton(Button):
|
2017-09-21 20:01:04 +03:00
|
|
|
def __init__(self, driver):
|
2023-03-21 08:38:42 +02:00
|
|
|
super().__init__(driver, accessibility_id="login-button")
|
2017-09-21 20:01:04 +03:00
|
|
|
|
2018-01-14 19:43:36 +02:00
|
|
|
def navigate(self):
|
|
|
|
from views.home_view import HomeView
|
|
|
|
return HomeView(self.driver)
|
|
|
|
|
2020-02-12 12:10:19 +02:00
|
|
|
|
2023-05-04 16:26:59 +02:00
|
|
|
class UserProfileElement(Button):
|
2024-06-07 21:21:29 +03:00
|
|
|
def __init__(self, driver, username: str = None, index: int = None):
|
2023-05-04 16:26:59 +02:00
|
|
|
self.username = username
|
2024-06-07 21:21:29 +03:00
|
|
|
self.index = index
|
|
|
|
if username:
|
|
|
|
super().__init__(
|
|
|
|
driver,
|
|
|
|
xpath="//*[@text='%s']//ancestor::android.view.ViewGroup[@content-desc='profile-card']" % self.username)
|
|
|
|
elif index:
|
|
|
|
super().__init__(driver, xpath="(//*[@content-desc='profile-card'])[%s]" % self.index)
|
|
|
|
else:
|
|
|
|
raise AttributeError("Either username or profile index should be defined")
|
2023-05-04 16:26:59 +02:00
|
|
|
|
|
|
|
def open_user_options(self):
|
|
|
|
Button(self.driver, xpath='%s//*[@content-desc="profile-card-options"]' % self.locator).click()
|
|
|
|
|
|
|
|
|
2018-01-03 11:34:40 +02:00
|
|
|
class SignInView(BaseView):
|
2017-09-21 20:01:04 +03:00
|
|
|
|
2021-02-26 16:27:20 +01:00
|
|
|
def __init__(self, driver):
|
|
|
|
super().__init__(driver)
|
2017-09-21 20:01:04 +03:00
|
|
|
self.driver = driver
|
2019-07-09 14:37:18 +03:00
|
|
|
|
2023-03-06 14:42:30 +00:00
|
|
|
# intro screen
|
|
|
|
self.i_m_new_in_status_button = Button(self.driver, accessibility_id="new-to-status-button")
|
|
|
|
|
2024-11-04 16:33:03 +01:00
|
|
|
self.explore_new_status_button = Button(self.driver, accessibility_id="explore-new-status")
|
2024-06-25 11:03:10 +08:00
|
|
|
self.create_profile_button = Button(self.driver, accessibility_id='new-to-status-button')
|
2024-11-13 16:35:59 +02:00
|
|
|
self.log_in_button = Button(self.driver, accessibility_id='log-in')
|
2024-11-26 20:37:44 +02:00
|
|
|
self.maybe_later_button = Button(self.driver, accessibility_id="maybe-later-button")
|
2024-11-27 15:47:12 +02:00
|
|
|
self.log_in_by_syncing_button = Button(self.driver, accessibility_id="log-in-by-syncing-icon-card")
|
2024-10-03 16:34:43 +03:00
|
|
|
self.enter_sync_code_button = Button(self.driver, accessibility_id="Enter sync code")
|
|
|
|
self.enter_sync_code_input = EditBox(self.driver, accessibility_id="enter-sync-code-input")
|
|
|
|
self.progress_screen_title = Text(self.driver, accessibility_id="progress-screen-title")
|
|
|
|
self.try_seed_phrase_button = Button(self.driver, accessibility_id="try-seed-phrase-button")
|
2024-06-25 11:03:10 +08:00
|
|
|
|
2021-02-26 16:27:20 +01:00
|
|
|
# migrate multiaccount
|
2021-06-18 14:09:03 +03:00
|
|
|
self.options_button = Button(self.driver, xpath="//androidx.appcompat.widget.LinearLayoutCompat")
|
2021-02-26 16:27:20 +01:00
|
|
|
self.manage_keys_and_storage_button = Button(self.driver, accessibility_id="manage-keys-and-storage-button")
|
2020-07-09 13:37:10 +02:00
|
|
|
|
2023-03-30 15:14:27 +02:00
|
|
|
# New onboarding
|
2024-11-22 18:35:46 +02:00
|
|
|
self.start_fresh_lets_go_button = Button(self.driver, accessibility_id="start-fresh-main-card")
|
2024-03-22 14:10:51 +01:00
|
|
|
self.profile_title_input = EditBox(self.driver, accessibility_id="profile-title-input")
|
2024-12-09 13:55:47 -06:00
|
|
|
self.profile_confirm_password_button = Button(self.driver, accessibility_id="Confirm password")
|
2024-11-22 18:35:46 +02:00
|
|
|
self.use_recovery_phrase_button = Button(self.driver, accessibility_id="use-a-recovery-phrase-icon-card")
|
2023-05-04 16:26:59 +02:00
|
|
|
self.passphrase_edit_box = EditBox(self.driver, accessibility_id="passphrase-input")
|
2023-07-24 18:25:36 +03:00
|
|
|
self.show_profiles_button = Button(self.driver, accessibility_id="show-profiles")
|
|
|
|
self.plus_profiles_button = Button(self.driver, accessibility_id="show-new-account-options")
|
|
|
|
self.create_new_profile_button = Button(self.driver, accessibility_id="create-new-profile")
|
2024-10-03 16:34:43 +03:00
|
|
|
self.sync_or_recover_new_profile_button = Button(self.driver, accessibility_id="multi-profile")
|
2023-05-04 16:26:59 +02:00
|
|
|
self.remove_profile_button = Button(self.driver, accessibility_id="remove-profile")
|
2023-03-30 15:14:27 +02:00
|
|
|
|
|
|
|
def set_password(self, password: str):
|
2024-04-05 18:46:23 +03:00
|
|
|
input_elements = self.password_input.wait_for_elements()
|
|
|
|
input_elements[0].send_keys(password)
|
|
|
|
input_elements[1].click()
|
|
|
|
input_elements[1].send_keys(password)
|
2023-03-30 15:14:27 +02:00
|
|
|
self.profile_confirm_password_button.click()
|
|
|
|
|
2024-12-09 13:55:47 -06:00
|
|
|
def create_user(self, password=common_password, first_user=True, enable_notifications=False):
|
2024-11-19 19:38:52 +02:00
|
|
|
self.driver.info("## Creating new multiaccount with password:'%s'" % password, device=False)
|
2023-11-06 14:12:04 +02:00
|
|
|
if first_user:
|
2024-11-22 18:35:46 +02:00
|
|
|
self.create_profile_button.click_until_presence_of_element(self.start_fresh_lets_go_button)
|
2024-11-26 20:37:44 +02:00
|
|
|
self.maybe_later_button.wait_and_click()
|
2023-11-03 15:34:33 +02:00
|
|
|
else:
|
2023-11-06 14:12:04 +02:00
|
|
|
if self.show_profiles_button.is_element_displayed(20):
|
|
|
|
self.show_profiles_button.click()
|
2023-10-19 01:17:11 +03:00
|
|
|
self.plus_profiles_button.click()
|
|
|
|
self.create_new_profile_button.click()
|
2024-11-22 18:35:46 +02:00
|
|
|
self.start_fresh_lets_go_button.click_until_presence_of_element(self.profile_title_input)
|
2023-03-30 15:14:27 +02:00
|
|
|
self.set_password(password)
|
2022-10-26 17:14:25 +02:00
|
|
|
self.chats_tab.wait_for_visibility_of_element(30)
|
2021-10-25 18:05:22 +02:00
|
|
|
self.driver.info("## New multiaccount is created successfully!", device=False)
|
2024-11-19 19:38:52 +02:00
|
|
|
home_view = self.get_home_view()
|
|
|
|
if enable_notifications:
|
|
|
|
profile_view = home_view.profile_button.click()
|
|
|
|
profile_view.switch_push_notifications()
|
|
|
|
profile_view.click_system_back_button(times=2)
|
|
|
|
return home_view
|
2018-03-01 15:22:01 +02:00
|
|
|
|
2024-11-19 19:38:52 +02:00
|
|
|
def recover_access(self, passphrase: str, password: str = common_password, enable_notifications=False,
|
2024-12-09 13:55:47 -06:00
|
|
|
second_user=False, after_sync_code=False):
|
2024-11-19 19:38:52 +02:00
|
|
|
self.driver.info("## Recover access (password:%s)" % password, device=False)
|
2023-03-30 15:14:27 +02:00
|
|
|
|
2024-10-03 16:34:43 +03:00
|
|
|
if not after_sync_code:
|
|
|
|
if not second_user:
|
2024-11-22 18:35:46 +02:00
|
|
|
self.create_profile_button.click_until_presence_of_element(self.start_fresh_lets_go_button)
|
2024-11-26 20:37:44 +02:00
|
|
|
self.maybe_later_button.wait_and_click()
|
2024-10-03 16:34:43 +03:00
|
|
|
else:
|
|
|
|
self.plus_profiles_button.click()
|
|
|
|
self.create_new_profile_button.click()
|
|
|
|
self.use_recovery_phrase_button.click()
|
2023-09-06 06:07:12 +03:00
|
|
|
self.passphrase_edit_box.send_keys(passphrase)
|
2024-03-22 14:10:51 +01:00
|
|
|
self.continue_button.click_until_presence_of_element(self.profile_title_input)
|
2023-03-30 15:14:27 +02:00
|
|
|
self.set_password(password)
|
|
|
|
self.chats_tab.wait_for_visibility_of_element(30)
|
2021-10-25 18:05:22 +02:00
|
|
|
self.driver.info("## Multiaccount is recovered successfully!", device=False)
|
2024-11-19 19:38:52 +02:00
|
|
|
home_view = self.get_home_view()
|
|
|
|
if enable_notifications:
|
|
|
|
profile_view = home_view.profile_button.click()
|
|
|
|
profile_view.switch_push_notifications()
|
|
|
|
return home_view
|
2018-05-02 19:01:17 +03:00
|
|
|
|
2024-10-03 16:34:43 +03:00
|
|
|
def sync_profile(self, sync_code: str, first_user: bool = True):
|
|
|
|
if first_user:
|
2024-11-13 16:35:59 +02:00
|
|
|
self.log_in_button.click()
|
2024-11-27 15:47:12 +02:00
|
|
|
self.maybe_later_button.click()
|
2024-10-03 16:34:43 +03:00
|
|
|
else:
|
|
|
|
self.plus_profiles_button.click()
|
|
|
|
self.sync_or_recover_new_profile_button.click()
|
2024-11-27 15:47:12 +02:00
|
|
|
self.log_in_by_syncing_button.click()
|
2024-10-03 16:34:43 +03:00
|
|
|
for checkbox in self.checkbox_button.find_elements():
|
|
|
|
checkbox.click()
|
|
|
|
self.continue_button.click()
|
|
|
|
self.enter_sync_code_button.click()
|
|
|
|
self.enter_sync_code_input.send_keys(sync_code)
|
|
|
|
self.confirm_button.click()
|
|
|
|
|
2024-11-20 13:51:06 -06:00
|
|
|
def sign_in(self, user_name, password=common_password):
|
2023-12-26 13:52:10 +02:00
|
|
|
self.driver.info("## Sign in (password: %s)" % password, device=False)
|
2024-11-20 13:51:06 -06:00
|
|
|
self.get_user_profile_by_name(user_name).click()
|
2023-12-26 13:52:10 +02:00
|
|
|
self.password_input.wait_for_visibility_of_element(10)
|
|
|
|
self.password_input.send_keys(password)
|
|
|
|
self.login_button.click()
|
2021-10-25 18:05:22 +02:00
|
|
|
self.driver.info("## Signed in successfully!", device=False)
|
2019-10-30 20:21:21 +02:00
|
|
|
return self.get_home_view()
|
2018-04-26 08:22:11 +02:00
|
|
|
|
2024-06-07 21:21:29 +03:00
|
|
|
def get_user_profile_by_name(self, username: str):
|
2023-05-04 16:26:59 +02:00
|
|
|
self.driver.info("Getting username card by '%s'" % username)
|
2024-06-07 21:21:29 +03:00
|
|
|
expected_element = UserProfileElement(self.driver, username=username)
|
2024-12-10 19:26:53 +02:00
|
|
|
if expected_element.is_element_displayed(10):
|
|
|
|
return expected_element
|
|
|
|
else:
|
|
|
|
raise NoSuchElementException(msg="User %s is not found!" % username)
|
2024-06-07 21:21:29 +03:00
|
|
|
|